xref: /dpdk/doc/guides/prog_guide/ethdev/flow_offload.rst (revision 16158f34900075f2f30b879bf3708e54e07455f4)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright 2016 6WIND S.A.
3    Copyright 2016 Mellanox Technologies, Ltd
4
5Generic flow API
6================
7
8Overview
9--------
10
11This API provides a generic means to configure hardware to match specific
12traffic, alter its fate and query related counters according to any
13number of user-defined rules.
14
15It is named *rte_flow* after the prefix used for all its symbols, and is
16defined in ``rte_flow.h``.
17
18- Matching can be performed on packet data (protocol headers, payload) and
19  properties (e.g. associated physical port, virtual device function ID).
20
21- Possible operations include dropping traffic, diverting it to specific
22  queues, to virtual/physical device functions or ports, performing tunnel
23  offloads, adding marks and so on.
24
25Flow rule
26---------
27
28Description
29~~~~~~~~~~~
30
31A flow rule is the combination of attributes with a matching pattern and a
32list of actions. Flow rules form the basis of this API.
33
34Flow rules can have several distinct actions (such as counting,
35encapsulating, decapsulating before redirecting packets to a particular
36queue, etc.), instead of relying on several rules to achieve this and having
37applications deal with hardware implementation details regarding their
38order.
39
40Support for different priority levels on a rule basis is provided, for
41example in order to force a more specific rule to come before a more generic
42one for packets matched by both. However hardware support for more than a
43single priority level cannot be guaranteed. When supported, the number of
44available priority levels is usually low, which is why they can also be
45implemented in software by PMDs (e.g. missing priority levels may be
46emulated by reordering rules).
47
48In order to remain as hardware-agnostic as possible, by default all rules
49are considered to have the same priority, which means that the order between
50overlapping rules (when a packet is matched by several filters) is
51undefined.
52
53PMDs may refuse to create overlapping rules at a given priority level when
54they can be detected (e.g. if a pattern matches an existing filter).
55
56Thus predictable results for a given priority level can only be achieved
57with non-overlapping rules, using perfect matching on all protocol layers.
58
59Flow rules can also be grouped, the flow rule priority is specific to the
60group they belong to. All flow rules in a given group are thus processed within
61the context of that group. Groups are not linked by default, so the logical
62hierarchy of groups must be explicitly defined by flow rules themselves in each
63group using the JUMP action to define the next group to redirect to. Only flow
64rules defined in the default group 0 are guaranteed to be matched against. This
65makes group 0 the origin of any group hierarchy defined by an application.
66
67Support for multiple actions per rule may be implemented internally on top
68of non-default hardware priorities. As a result, both features may not be
69simultaneously available to applications.
70
71Considering that allowed pattern/actions combinations cannot be known in
72advance and would result in an impractically large number of capabilities to
73expose, a method is provided to validate a given rule from the current
74device configuration state.
75
76This enables applications to check if the rule types they need is supported
77at initialization time, before starting their data path. This method can be
78used anytime, its only requirement being that the resources needed by a rule
79should exist (e.g. a target RX queue should be configured first).
80
81Each defined rule is associated with an opaque handle managed by the PMD,
82applications are responsible for keeping it. These can be used for queries
83and rules management, such as retrieving counters or other data and
84destroying them.
85
86To avoid resource leaks on the PMD side, handles must be explicitly
87destroyed by the application before releasing associated resources such as
88queues and ports.
89
90.. warning::
91
92   The following description of rule persistence is an experimental behavior
93   that may change without a prior notice.
94
95When the device is stopped, its rules do not process the traffic.
96In particular, transfer rules created using some device
97stop affecting the traffic even if they refer to different ports.
98
99If ``RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP`` is not advertised,
100rules cannot be created until the device is started for the first time
101and cannot be kept when the device is stopped.
102However, PMD also does not flush them automatically on stop,
103so the application must call ``rte_flow_flush()`` or ``rte_flow_destroy()``
104before stopping the device to ensure no rules remain.
105
106If ``RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP`` is advertised, this means
107the PMD can keep at least some rules across the device stop and start.
108However, ``rte_eth_dev_configure()`` may fail if any rules remain,
109so the application must flush them before attempting a reconfiguration.
110Keeping may be unsupported for some types of rule items and actions,
111as well as depending on the value of flow attributes transfer bit.
112A combination of a single an item or action type
113and a value of the transfer bit is called a rule feature.
114For example: a COUNT action with the transfer bit set.
115To test if rules with a particular feature are kept, the application must try
116to create a valid rule using this feature when the device is not started
117(either before the first start or after a stop).
118If it fails with an error of type ``RTE_FLOW_ERROR_TYPE_STATE``,
119all rules using this feature must be flushed by the application
120before stopping the device.
121If it succeeds, such rules will be kept when the device is stopped,
122provided they do not use other features that are not supported.
123Rules that are created when the device is stopped, including the rules
124created for the test, will be kept after the device is started.
125
126The following sections cover:
127
128- **Attributes** (represented by ``struct rte_flow_attr``): properties of a
129  flow rule such as its direction (ingress or egress) and priority.
130
131- **Pattern item** (represented by ``struct rte_flow_item``): part of a
132  matching pattern that either matches specific packet data or traffic
133  properties. It can also describe properties of the pattern itself, such as
134  inverted matching.
135
136- **Matching pattern**: traffic properties to look for, a combination of any
137  number of items.
138
139- **Actions** (represented by ``struct rte_flow_action``): operations to
140  perform whenever a packet is matched by a pattern.
141
142Attributes
143~~~~~~~~~~
144
145Attribute: Group
146^^^^^^^^^^^^^^^^
147
148Flow rules can be grouped by assigning them a common group number. Groups
149allow a logical hierarchy of flow rule groups (tables) to be defined. These
150groups can be supported virtually in the PMD or in the physical device.
151Group 0 is the default group and is the only group that
152flows are guaranteed to be matched against.
153All subsequent groups can only be reached by using a JUMP action
154from a matched flow rule.
155
156Although optional, applications are encouraged to group similar rules as
157much as possible to fully take advantage of hardware capabilities
158(e.g. optimized matching) and work around limitations (e.g. a single pattern
159type possibly allowed in a given group), while being aware that the groups'
160hierarchies must be programmed explicitly.
161
162Note that support for more than a single group is not guaranteed.
163
164Attribute: Priority
165^^^^^^^^^^^^^^^^^^^
166
167A priority level can be assigned to a flow rule, lower values
168denote higher priority, with 0 as the maximum.
169
170Priority levels are arbitrary and up to the application, they do
171not need to be contiguous nor start from 0, however the maximum number
172varies between devices and may be affected by existing flow rules.
173
174A flow which matches multiple rules in the same group will always be matched by
175the rule with the highest priority in that group.
176
177If a packet is matched by several rules of a given group for a given
178priority level, the outcome is undefined. It can take any path, may be
179duplicated or even cause unrecoverable errors.
180
181Note that support for more than a single priority level is not guaranteed.
182
183Attribute: Traffic direction
184^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185
186Unless `Attribute: Transfer`_ is specified, flow rule patterns apply
187to inbound and / or outbound traffic. With this respect, ``ingress``
188and ``egress`` respectively stand for **inbound** and **outbound**
189based on the standpoint of the application creating a flow rule.
190
191Several pattern items and actions are valid and can be used in both
192directions. At least one direction must be specified.
193
194Specifying both directions at once for a given rule is not recommended but
195may be valid in a few cases.
196
197Attribute: Transfer
198^^^^^^^^^^^^^^^^^^^
199
200Instead of simply matching the properties of traffic as it would appear on a
201given DPDK port ID, enabling this attribute transfers a flow rule to the
202lowest possible level of any device endpoints found in the pattern.
203
204When supported, this effectively enables an application to reroute traffic
205not necessarily intended for it (e.g. coming from or addressed to different
206physical ports, VFs or applications) at the device level.
207
208In "transfer" flows, the use of `Attribute: Traffic direction`_ in not allowed.
209One may use `Item: PORT_REPRESENTOR`_ and `Item: REPRESENTED_PORT`_ instead.
210
211Pattern item
212~~~~~~~~~~~~
213
214Pattern items fall in two categories:
215
216- Matching protocol headers and packet data, usually associated with a
217  specification structure. These must be stacked in the same order as the
218  protocol layers to match inside packets, starting from the lowest.
219
220- Matching meta-data or affecting pattern processing, often without a
221  specification structure. Since they do not match packet contents, their
222  position in the list is usually not relevant.
223
224Item specification structures are used to match specific values among
225protocol fields (or item properties). Documentation describes for each item
226whether they are associated with one and their type name if so.
227
228Up to three structures of the same type can be set for a given item:
229
230- ``spec``: values to match (e.g. a given IPv4 address).
231
232- ``last``: upper bound for an inclusive range with corresponding fields in
233  ``spec``.
234
235- ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
236  to distinguish the values to take into account and/or partially mask them
237  out (e.g. in order to match an IPv4 address prefix).
238
239Usage restrictions and expected behavior:
240
241- Setting either ``mask`` or ``last`` without ``spec`` is an error.
242
243- Field values in ``last`` which are either 0 or equal to the corresponding
244  values in ``spec`` are ignored; they do not generate a range. Nonzero
245  values lower than those in ``spec`` are not supported.
246
247- Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
248  to use the default mask defined for that item (defined as
249  ``rte_flow_item_{name}_mask`` constants).
250
251- Not setting any of them (assuming item type allows it) is equivalent to
252  providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
253
254- ``mask`` is a simple bit-mask applied before interpreting the contents of
255  ``spec`` and ``last``, which may yield unexpected results if not used
256  carefully. For example, if for an IPv4 address field, ``spec`` provides
257  *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
258  *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
259
260Example of an item specification matching an Ethernet header:
261
262.. _table_rte_flow_pattern_item_example:
263
264.. table:: Ethernet item
265
266   +----------+----------+-----------------------+
267   | Field    | Subfield | Value                 |
268   +==========+==========+=======================+
269   | ``spec`` | ``src``  | ``00:00:01:02:03:04`` |
270   |          +----------+-----------------------+
271   |          | ``dst``  | ``00:00:2a:66:00:01`` |
272   |          +----------+-----------------------+
273   |          | ``type`` | ``0x22aa``            |
274   +----------+----------+-----------------------+
275   | ``last`` | unspecified                      |
276   +----------+----------+-----------------------+
277   | ``mask`` | ``src``  | ``00:00:ff:ff:ff:00`` |
278   |          +----------+-----------------------+
279   |          | ``dst``  | ``00:00:00:00:00:ff`` |
280   |          +----------+-----------------------+
281   |          | ``type`` | ``0x0000``            |
282   +----------+----------+-----------------------+
283
284Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
285with the following properties are thus matched:
286
287- ``src``: ``??:??:01:02:03:??``
288- ``dst``: ``??:??:??:??:??:01``
289- ``type``: ``0x????``
290
291Matching pattern
292~~~~~~~~~~~~~~~~
293
294A pattern is formed by stacking items starting from the lowest protocol
295layer to match. This stacking restriction does not apply to meta items which
296can be placed anywhere in the stack without affecting the meaning of the
297resulting pattern.
298
299Patterns are terminated by END items.
300
301Examples:
302
303.. _table_rte_flow_tcpv4_as_l4:
304
305.. table:: TCPv4 as L4
306
307   +-------+----------+
308   | Index | Item     |
309   +=======+==========+
310   | 0     | Ethernet |
311   +-------+----------+
312   | 1     | IPv4     |
313   +-------+----------+
314   | 2     | TCP      |
315   +-------+----------+
316   | 3     | END      |
317   +-------+----------+
318
319|
320
321.. _table_rte_flow_tcpv6_in_vxlan:
322
323.. table:: TCPv6 in VXLAN
324
325   +-------+------------+
326   | Index | Item       |
327   +=======+============+
328   | 0     | Ethernet   |
329   +-------+------------+
330   | 1     | IPv4       |
331   +-------+------------+
332   | 2     | UDP        |
333   +-------+------------+
334   | 3     | VXLAN      |
335   +-------+------------+
336   | 4     | Ethernet   |
337   +-------+------------+
338   | 5     | IPv6       |
339   +-------+------------+
340   | 6     | TCP        |
341   +-------+------------+
342   | 7     | END        |
343   +-------+------------+
344
345|
346
347.. _table_rte_flow_tcpv4_as_l4_meta:
348
349.. table:: TCPv4 as L4 with meta items
350
351   +-------+----------+
352   | Index | Item     |
353   +=======+==========+
354   | 0     | VOID     |
355   +-------+----------+
356   | 1     | Ethernet |
357   +-------+----------+
358   | 2     | VOID     |
359   +-------+----------+
360   | 3     | IPv4     |
361   +-------+----------+
362   | 4     | TCP      |
363   +-------+----------+
364   | 5     | VOID     |
365   +-------+----------+
366   | 6     | VOID     |
367   +-------+----------+
368   | 7     | END      |
369   +-------+----------+
370
371The above example shows how meta items do not affect packet data matching
372items, as long as those remain stacked properly. The resulting matching
373pattern is identical to "TCPv4 as L4".
374
375.. _table_rte_flow_udpv6_anywhere:
376
377.. table:: UDPv6 anywhere
378
379   +-------+------+
380   | Index | Item |
381   +=======+======+
382   | 0     | IPv6 |
383   +-------+------+
384   | 1     | UDP  |
385   +-------+------+
386   | 2     | END  |
387   +-------+------+
388
389If supported by the PMD, omitting one or several protocol layers at the
390bottom of the stack as in the above example (missing an Ethernet
391specification) enables looking up anywhere in packets.
392
393It is unspecified whether the payload of supported encapsulations
394(e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
395outer or both packets.
396
397.. _table_rte_flow_invalid_l3:
398
399.. table:: Invalid, missing L3
400
401   +-------+----------+
402   | Index | Item     |
403   +=======+==========+
404   | 0     | Ethernet |
405   +-------+----------+
406   | 1     | UDP      |
407   +-------+----------+
408   | 2     | END      |
409   +-------+----------+
410
411The above pattern is invalid due to a missing L3 specification between L2
412(Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
413top of the stack.
414
415Meta item types
416~~~~~~~~~~~~~~~
417
418They match meta-data or affect pattern processing instead of matching packet
419data directly, most of them do not need a specification structure. This
420particularity allows them to be specified anywhere in the stack without
421causing any side effect.
422
423Item: ``END``
424^^^^^^^^^^^^^
425
426End marker for item lists. Prevents further processing of items, thereby
427ending the pattern.
428
429- Its numeric value is 0 for convenience.
430- PMD support is mandatory.
431- ``spec``, ``last`` and ``mask`` are ignored.
432
433.. _table_rte_flow_item_end:
434
435.. table:: END
436
437   +----------+---------+
438   | Field    | Value   |
439   +==========+=========+
440   | ``spec`` | ignored |
441   +----------+---------+
442   | ``last`` | ignored |
443   +----------+---------+
444   | ``mask`` | ignored |
445   +----------+---------+
446
447Item: ``VOID``
448^^^^^^^^^^^^^^
449
450Used as a placeholder for convenience. It is ignored and simply discarded by
451PMDs.
452
453- PMD support is mandatory.
454- ``spec``, ``last`` and ``mask`` are ignored.
455
456.. _table_rte_flow_item_void:
457
458.. table:: VOID
459
460   +----------+---------+
461   | Field    | Value   |
462   +==========+=========+
463   | ``spec`` | ignored |
464   +----------+---------+
465   | ``last`` | ignored |
466   +----------+---------+
467   | ``mask`` | ignored |
468   +----------+---------+
469
470One usage example for this type is generating rules that share a common
471prefix quickly without reallocating memory, only by updating item types:
472
473.. _table_rte_flow_item_void_example:
474
475.. table:: TCP, UDP or ICMP as L4
476
477   +-------+--------------------+
478   | Index | Item               |
479   +=======+====================+
480   | 0     | Ethernet           |
481   +-------+--------------------+
482   | 1     | IPv4               |
483   +-------+------+------+------+
484   | 2     | UDP  | VOID | VOID |
485   +-------+------+------+------+
486   | 3     | VOID | TCP  | VOID |
487   +-------+------+------+------+
488   | 4     | VOID | VOID | ICMP |
489   +-------+------+------+------+
490   | 5     | END                |
491   +-------+--------------------+
492
493Item: ``INVERT``
494^^^^^^^^^^^^^^^^
495
496Inverted matching, i.e. process packets that do not match the pattern.
497
498- ``spec``, ``last`` and ``mask`` are ignored.
499
500.. _table_rte_flow_item_invert:
501
502.. table:: INVERT
503
504   +----------+---------+
505   | Field    | Value   |
506   +==========+=========+
507   | ``spec`` | ignored |
508   +----------+---------+
509   | ``last`` | ignored |
510   +----------+---------+
511   | ``mask`` | ignored |
512   +----------+---------+
513
514Usage example, matching non-TCPv4 packets only:
515
516.. _table_rte_flow_item_invert_example:
517
518.. table:: Anything but TCPv4
519
520   +-------+----------+
521   | Index | Item     |
522   +=======+==========+
523   | 0     | INVERT   |
524   +-------+----------+
525   | 1     | Ethernet |
526   +-------+----------+
527   | 2     | IPv4     |
528   +-------+----------+
529   | 3     | TCP      |
530   +-------+----------+
531   | 4     | END      |
532   +-------+----------+
533
534Item: ``PORT_ID``
535^^^^^^^^^^^^^^^^^
536
537This item is deprecated. Consider:
538 - `Item: PORT_REPRESENTOR`_
539 - `Item: REPRESENTED_PORT`_
540
541Matches traffic originating from (ingress) or going to (egress) a given DPDK
542port ID.
543
544Normally only supported if the port ID in question is known by the
545underlying PMD and related to the device the flow rule is created against.
546
547- Default ``mask`` matches the specified DPDK port ID.
548
549.. _table_rte_flow_item_port_id:
550
551.. table:: PORT_ID
552
553   +----------+----------+-----------------------------+
554   | Field    | Subfield | Value                       |
555   +==========+==========+=============================+
556   | ``spec`` | ``id``   | DPDK port ID                |
557   +----------+----------+-----------------------------+
558   | ``last`` | ``id``   | upper range value           |
559   +----------+----------+-----------------------------+
560   | ``mask`` | ``id``   | zeroed to match any port ID |
561   +----------+----------+-----------------------------+
562
563Item: ``MARK``
564^^^^^^^^^^^^^^
565
566Matches an arbitrary integer value which was set using the ``MARK`` action in
567a previously matched rule.
568
569This item can only specified once as a match criteria as the ``MARK`` action can
570only be specified once in a flow action.
571
572Note the value of MARK field is arbitrary and application defined.
573
574Depending on the underlying implementation the MARK item may be supported on
575the physical device, with virtual groups in the PMD or not at all.
576
577- Default ``mask`` matches any integer value.
578
579.. _table_rte_flow_item_mark:
580
581.. table:: MARK
582
583   +----------+----------+---------------------------+
584   | Field    | Subfield | Value                     |
585   +==========+==========+===========================+
586   | ``spec`` | ``id``   | integer value             |
587   +----------+--------------------------------------+
588   | ``last`` | ``id``   | upper range value         |
589   +----------+----------+---------------------------+
590   | ``mask`` | ``id``   | zeroed to match any value |
591   +----------+----------+---------------------------+
592
593Item: ``TAG``
594^^^^^^^^^^^^^
595
596Matches tag item set by other flows. Multiple tags are supported by specifying
597``index``.
598
599- Default ``mask`` matches the specified tag value and index.
600
601.. _table_rte_flow_item_tag:
602
603.. table:: TAG
604
605   +----------+----------+----------------------------------------+
606   | Field    | Subfield  | Value                                 |
607   +==========+===========+=======================================+
608   | ``spec`` | ``data``  | 32 bit flow tag value                 |
609   |          +-----------+---------------------------------------+
610   |          | ``index`` | index of flow tag                     |
611   +----------+-----------+---------------------------------------+
612   | ``last`` | ``data``  | upper range value                     |
613   |          +-----------+---------------------------------------+
614   |          | ``index`` | field is ignored                      |
615   +----------+-----------+---------------------------------------+
616   | ``mask`` | ``data``  | bit-mask applies to "spec" and "last" |
617   |          +-----------+---------------------------------------+
618   |          | ``index`` | field is ignored                      |
619   +----------+-----------+---------------------------------------+
620
621Item: ``META``
622^^^^^^^^^^^^^^^^^
623
624Matches 32 bit metadata item set.
625
626On egress, metadata can be set either by mbuf metadata field with
627RTE_MBUF_DYNFLAG_TX_METADATA flag or ``SET_META`` action. On ingress, ``SET_META``
628action sets metadata for a packet and the metadata will be reported via
629``metadata`` dynamic field of ``rte_mbuf`` with RTE_MBUF_DYNFLAG_RX_METADATA flag.
630
631- Default ``mask`` matches the specified Rx metadata value.
632
633.. _table_rte_flow_item_meta:
634
635.. table:: META
636
637   +----------+----------+---------------------------------------+
638   | Field    | Subfield | Value                                 |
639   +==========+==========+=======================================+
640   | ``spec`` | ``data`` | 32 bit metadata value                 |
641   +----------+----------+---------------------------------------+
642   | ``last`` | ``data`` | upper range value                     |
643   +----------+----------+---------------------------------------+
644   | ``mask`` | ``data`` | bit-mask applies to "spec" and "last" |
645   +----------+----------+---------------------------------------+
646
647Data matching item types
648~~~~~~~~~~~~~~~~~~~~~~~~
649
650Most of these are basically protocol header definitions with associated
651bit-masks. They must be specified (stacked) from lowest to highest protocol
652layer to form a matching pattern.
653
654Item: ``ANY``
655^^^^^^^^^^^^^
656
657Matches any protocol in place of the current layer, a single ANY may also
658stand for several protocol layers.
659
660This is usually specified as the first pattern item when looking for a
661protocol anywhere in a packet.
662
663- Default ``mask`` stands for any number of layers.
664
665.. _table_rte_flow_item_any:
666
667.. table:: ANY
668
669   +----------+----------+--------------------------------------+
670   | Field    | Subfield | Value                                |
671   +==========+==========+======================================+
672   | ``spec`` | ``num``  | number of layers covered             |
673   +----------+----------+--------------------------------------+
674   | ``last`` | ``num``  | upper range value                    |
675   +----------+----------+--------------------------------------+
676   | ``mask`` | ``num``  | zeroed to cover any number of layers |
677   +----------+----------+--------------------------------------+
678
679Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
680and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
681or IPv6) matched by the second ANY specification:
682
683.. _table_rte_flow_item_any_example:
684
685.. table:: TCP in VXLAN with wildcards
686
687   +-------+------+----------+----------+-------+
688   | Index | Item | Field    | Subfield | Value |
689   +=======+======+==========+==========+=======+
690   | 0     | Ethernet                           |
691   +-------+------+----------+----------+-------+
692   | 1     | ANY  | ``spec`` | ``num``  | 2     |
693   +-------+------+----------+----------+-------+
694   | 2     | VXLAN                              |
695   +-------+------------------------------------+
696   | 3     | Ethernet                           |
697   +-------+------+----------+----------+-------+
698   | 4     | ANY  | ``spec`` | ``num``  | 1     |
699   +-------+------+----------+----------+-------+
700   | 5     | TCP                                |
701   +-------+------------------------------------+
702   | 6     | END                                |
703   +-------+------------------------------------+
704
705Item: ``RAW``
706^^^^^^^^^^^^^
707
708Matches a byte string of a given length at a given offset.
709
710Offset is either absolute (using the start of the packet) or relative to the
711end of the previous matched item in the stack, in which case negative values
712are allowed.
713
714If search is enabled, offset is used as the starting point. The search area
715can be delimited by setting limit to a nonzero value, which is the maximum
716number of bytes after offset where the pattern may start.
717
718Matching a zero-length pattern is allowed, doing so resets the relative
719offset for subsequent items.
720
721- This type does not support ranges (``last`` field).
722- Default ``mask`` matches all fields exactly.
723
724.. _table_rte_flow_item_raw:
725
726.. table:: RAW
727
728   +----------+--------------+-------------------------------------------------+
729   | Field    | Subfield     | Value                                           |
730   +==========+==============+=================================================+
731   | ``spec`` | ``relative`` | look for pattern after the previous item        |
732   |          +--------------+-------------------------------------------------+
733   |          | ``search``   | search pattern from offset (see also ``limit``) |
734   |          +--------------+-------------------------------------------------+
735   |          | ``reserved`` | reserved, must be set to zero                   |
736   |          +--------------+-------------------------------------------------+
737   |          | ``offset``   | absolute or relative offset for ``pattern``     |
738   |          +--------------+-------------------------------------------------+
739   |          | ``limit``    | search area limit for start of ``pattern``      |
740   |          +--------------+-------------------------------------------------+
741   |          | ``length``   | ``pattern`` length                              |
742   |          +--------------+-------------------------------------------------+
743   |          | ``pattern``  | byte string to look for                         |
744   +----------+--------------+-------------------------------------------------+
745   | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
746   +----------+----------------------------------------------------------------+
747   | ``mask`` | bit-mask applied to ``spec`` values with usual behavior        |
748   +----------+----------------------------------------------------------------+
749
750Example pattern looking for several strings at various offsets of a UDP
751payload, using combined RAW items:
752
753.. _table_rte_flow_item_raw_example:
754
755.. table:: UDP payload matching
756
757   +-------+------+----------+--------------+-------+
758   | Index | Item | Field    | Subfield     | Value |
759   +=======+======+==========+==============+=======+
760   | 0     | Ethernet                               |
761   +-------+----------------------------------------+
762   | 1     | IPv4                                   |
763   +-------+----------------------------------------+
764   | 2     | UDP                                    |
765   +-------+------+----------+--------------+-------+
766   | 3     | RAW  | ``spec`` | ``relative`` | 1     |
767   |       |      |          +--------------+-------+
768   |       |      |          | ``search``   | 1     |
769   |       |      |          +--------------+-------+
770   |       |      |          | ``offset``   | 10    |
771   |       |      |          +--------------+-------+
772   |       |      |          | ``limit``    | 0     |
773   |       |      |          +--------------+-------+
774   |       |      |          | ``length``   | 3     |
775   |       |      |          +--------------+-------+
776   |       |      |          | ``pattern``  | "foo" |
777   +-------+------+----------+--------------+-------+
778   | 4     | RAW  | ``spec`` | ``relative`` | 1     |
779   |       |      |          +--------------+-------+
780   |       |      |          | ``search``   | 0     |
781   |       |      |          +--------------+-------+
782   |       |      |          | ``offset``   | 20    |
783   |       |      |          +--------------+-------+
784   |       |      |          | ``limit``    | 0     |
785   |       |      |          +--------------+-------+
786   |       |      |          | ``length``   | 3     |
787   |       |      |          +--------------+-------+
788   |       |      |          | ``pattern``  | "bar" |
789   +-------+------+----------+--------------+-------+
790   | 5     | RAW  | ``spec`` | ``relative`` | 1     |
791   |       |      |          +--------------+-------+
792   |       |      |          | ``search``   | 0     |
793   |       |      |          +--------------+-------+
794   |       |      |          | ``offset``   | -29   |
795   |       |      |          +--------------+-------+
796   |       |      |          | ``limit``    | 0     |
797   |       |      |          +--------------+-------+
798   |       |      |          | ``length``   | 3     |
799   |       |      |          +--------------+-------+
800   |       |      |          | ``pattern``  | "baz" |
801   +-------+------+----------+--------------+-------+
802   | 6     | END                                    |
803   +-------+----------------------------------------+
804
805This translates to:
806
807- Locate "foo" at least 10 bytes deep inside UDP payload.
808- Locate "bar" after "foo" plus 20 bytes.
809- Locate "baz" after "bar" minus 29 bytes.
810
811Such a packet may be represented as follows (not to scale)::
812
813 0                     >= 10 B           == 20 B
814 |                  |<--------->|     |<--------->|
815 |                  |           |     |           |
816 |-----|------|-----|-----|-----|-----|-----------|-----|------|
817 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
818 |-----|------|-----|-----|-----|-----|-----------|-----|------|
819                          |                             |
820                          |<--------------------------->|
821                                      == 29 B
822
823Note that matching subsequent pattern items would resume after "baz", not
824"bar" since matching is always performed after the previous item of the
825stack.
826
827Item: ``ETH``
828^^^^^^^^^^^^^
829
830Matches an Ethernet header.
831
832The ``type`` field either stands for "EtherType" or "TPID" when followed by
833so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
834the latter case, ``type`` refers to that of the outer header, with the inner
835EtherType/TPID provided by the subsequent pattern item. This is the same
836order as on the wire.
837If the ``type`` field contains a TPID value, then only tagged packets with the
838specified TPID will match the pattern.
839The field ``has_vlan`` can be used to match any type of tagged packets,
840instead of using the ``type`` field.
841If the ``type`` and ``has_vlan`` fields are not specified, then both tagged
842and untagged packets will match the pattern.
843
844- ``hdr``:  header definition (``rte_ether.h``).
845- ``has_vlan``: packet header contains at least one VLAN.
846- Default ``mask`` matches destination and source addresses only.
847
848Item: ``VLAN``
849^^^^^^^^^^^^^^
850
851Matches an 802.1Q/ad VLAN tag.
852
853The corresponding standard outer EtherType (TPID) values are
854``RTE_ETHER_TYPE_VLAN`` or ``RTE_ETHER_TYPE_QINQ``. It can be overridden by the
855preceding pattern item.
856If a ``VLAN`` item is present in the pattern, then only tagged packets will
857match the pattern.
858The field ``has_more_vlan`` can be used to match any type of tagged packets,
859instead of using the ``inner_type field``.
860If the ``inner_type`` and ``has_more_vlan`` fields are not specified,
861then any tagged packets will match the pattern.
862
863- ``hdr``:  header definition (``rte_ether.h``).
864- ``has_more_vlan``: packet header contains at least one more VLAN, after this VLAN.
865- Default ``mask`` matches the VID part of TCI only (lower 12 bits).
866
867Item: ``IPV4``
868^^^^^^^^^^^^^^
869
870Matches an IPv4 header.
871
872Note: IPv4 options are handled by dedicated pattern items.
873
874- ``hdr``: IPv4 header definition (``rte_ip.h``).
875- Default ``mask`` matches source and destination addresses only.
876
877Item: ``IPV6``
878^^^^^^^^^^^^^^
879
880Matches an IPv6 header.
881
882Dedicated flags indicate if header contains specific extension headers.
883To match on packets containing a specific extension header, an application
884should match on the dedicated flag set to 1.
885To match on packets not containing a specific extension header, an application
886should match on the dedicated flag clear to 0.
887In case application doesn't care about the existence of a specific extension
888header, it should not specify the dedicated flag for matching.
889
890- ``hdr``: IPv6 header definition (``rte_ip.h``).
891- ``has_hop_ext``: header contains Hop-by-Hop Options extension header.
892- ``has_route_ext``: header contains Routing extension header.
893- ``has_frag_ext``: header contains Fragment extension header.
894- ``has_auth_ext``: header contains Authentication extension header.
895- ``has_esp_ext``: header contains Encapsulation Security Payload extension header.
896- ``has_dest_ext``: header contains Destination Options extension header.
897- ``has_mobil_ext``: header contains Mobility extension header.
898- ``has_hip_ext``: header contains Host Identity Protocol extension header.
899- ``has_shim6_ext``: header contains Shim6 Protocol extension header.
900- Default ``mask`` matches ``hdr`` source and destination addresses only.
901
902Item: ``ICMP``
903^^^^^^^^^^^^^^
904
905Matches an ICMP header.
906
907- ``hdr``: ICMP header definition (``rte_icmp.h``).
908- Default ``mask`` matches ICMP type and code only.
909
910Item: ``UDP``
911^^^^^^^^^^^^^
912
913Matches a UDP header.
914
915- ``hdr``: UDP header definition (``rte_udp.h``).
916- Default ``mask`` matches source and destination ports only.
917
918Item: ``TCP``
919^^^^^^^^^^^^^
920
921Matches a TCP header.
922
923- ``hdr``: TCP header definition (``rte_tcp.h``).
924- Default ``mask`` matches source and destination ports only.
925
926Item: ``SCTP``
927^^^^^^^^^^^^^^
928
929Matches a SCTP header.
930
931- ``hdr``: SCTP header definition (``rte_sctp.h``).
932- Default ``mask`` matches source and destination ports only.
933
934Item: ``VXLAN``
935^^^^^^^^^^^^^^^
936
937Matches a VXLAN header (RFC 7348).
938
939- ``hdr``:  header definition (``rte_vxlan.h``).
940- Default ``mask`` matches VNI only.
941
942Item: ``E_TAG``
943^^^^^^^^^^^^^^^
944
945Matches an IEEE 802.1BR E-Tag header.
946
947The corresponding standard outer EtherType (TPID) value is
948``RTE_ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
949
950- ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
951  E-DEI (1b), ingress E-CID base (12b).
952- ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
953- ``in_ecid_e``: ingress E-CID ext.
954- ``ecid_e``: E-CID ext.
955- ``inner_type``: inner EtherType or TPID.
956- Default ``mask`` simultaneously matches GRP and E-CID base.
957
958Item: ``NVGRE``
959^^^^^^^^^^^^^^^
960
961Matches a NVGRE header (RFC 7637).
962
963- ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
964  sequence number (1b), reserved 0 (9b), version (3b). This field must have
965  value 0x2000 according to RFC 7637.
966- ``protocol``: protocol type (0x6558).
967- ``tni``: virtual subnet ID.
968- ``flow_id``: flow ID.
969- Default ``mask`` matches TNI only.
970
971Item: ``MPLS``
972^^^^^^^^^^^^^^
973
974Matches a MPLS header.
975
976- ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
977- Default ``mask`` matches label only.
978
979Item: ``GRE``
980^^^^^^^^^^^^^
981
982Matches a GRE header.
983
984- ``c_rsvd0_ver``: checksum, reserved 0 and version.
985- ``protocol``: protocol type.
986- Default ``mask`` matches protocol only.
987
988Item: ``GRE_KEY``
989^^^^^^^^^^^^^^^^^
990This action is deprecated. Consider `Item: GRE_OPTION`.
991
992Matches a GRE key field.
993This should be preceded by item ``GRE``.
994
995- Value to be matched is a big-endian 32 bit integer.
996- When this item present it implicitly match K bit in default mask as "1"
997
998Item: ``GRE_OPTION``
999^^^^^^^^^^^^^^^^^^^^
1000
1001Matches a GRE optional fields (checksum/key/sequence).
1002This should be preceded by item ``GRE``.
1003
1004- ``checksum``: checksum.
1005- ``key``: key.
1006- ``sequence``: sequence.
1007- The items in GRE_OPTION do not change bit flags(c_bit/k_bit/s_bit) in GRE
1008  item. The bit flags need be set with GRE item by application. When the items
1009  present, the corresponding bits in GRE spec and mask should be set "1" by
1010  application, it means to match specified value of the fields. When the items
1011  no present, but the corresponding bits in GRE spec and mask is "1", it means
1012  to match any value of the fields.
1013
1014Item: ``FUZZY``
1015^^^^^^^^^^^^^^^
1016
1017Fuzzy pattern match, expect faster than default.
1018
1019This is for device that support fuzzy match option. Usually a fuzzy match is
1020fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
1021value, but it is possible two different patterns have the same hash value.
1022
1023Matching accuracy level can be configured by threshold. Driver can divide the
1024range of threshold and map to different accuracy levels that device support.
1025
1026Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
1027means fuzziest match.
1028
1029.. _table_rte_flow_item_fuzzy:
1030
1031.. table:: FUZZY
1032
1033   +----------+---------------+--------------------------------------------------+
1034   | Field    |   Subfield    | Value                                            |
1035   +==========+===============+==================================================+
1036   | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
1037   +----------+---------------+--------------------------------------------------+
1038   | ``last`` | ``threshold`` | upper range value                                |
1039   +----------+---------------+--------------------------------------------------+
1040   | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last"              |
1041   +----------+---------------+--------------------------------------------------+
1042
1043Usage example, fuzzy match a TCPv4 packets:
1044
1045.. _table_rte_flow_item_fuzzy_example:
1046
1047.. table:: Fuzzy matching
1048
1049   +-------+----------+
1050   | Index | Item     |
1051   +=======+==========+
1052   | 0     | FUZZY    |
1053   +-------+----------+
1054   | 1     | Ethernet |
1055   +-------+----------+
1056   | 2     | IPv4     |
1057   +-------+----------+
1058   | 3     | TCP      |
1059   +-------+----------+
1060   | 4     | END      |
1061   +-------+----------+
1062
1063Item: ``GTP``, ``GTPC``, ``GTPU``
1064^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1065
1066Matches a GTPv1 header.
1067
1068Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1069are defined for a user-friendly API when creating GTP-C and GTP-U
1070flow rules.
1071
1072- ``hdr``:  header definition (``rte_gtp.h``).
1073- Default ``mask`` matches teid only.
1074
1075Item: ``ESP``
1076^^^^^^^^^^^^^
1077
1078Matches an ESP header.
1079
1080- ``hdr``: ESP header definition (``rte_esp.h``).
1081- Default ``mask`` matches SPI only.
1082
1083Item: ``GENEVE``
1084^^^^^^^^^^^^^^^^
1085
1086Matches a GENEVE header.
1087
1088- ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
1089  OAM packet (1b), critical options present (1b), reserved 0 (6b).
1090- ``protocol``: protocol type.
1091- ``vni``: virtual network identifier.
1092- ``rsvd1``: reserved, normally 0x00.
1093- Default ``mask`` matches VNI only.
1094
1095Item: ``VXLAN-GPE``
1096^^^^^^^^^^^^^^^^^^^
1097
1098Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1099
1100- ``hdr``:  header definition (``rte_vxlan.h``).
1101- Default ``mask`` matches VNI only.
1102
1103Item: ``ARP_ETH_IPV4``
1104^^^^^^^^^^^^^^^^^^^^^^
1105
1106Matches an ARP header for Ethernet/IPv4.
1107
1108- ``hdr``:  header definition (``rte_arp.h``).
1109- Default ``mask`` matches SHA, SPA, THA and TPA.
1110
1111Item: ``IPV6_EXT``
1112^^^^^^^^^^^^^^^^^^
1113
1114Matches the presence of any IPv6 extension header.
1115
1116- ``next_hdr``: next header.
1117- Default ``mask`` matches ``next_hdr``.
1118
1119Normally preceded by any of:
1120
1121- `Item: IPV6`_
1122- `Item: IPV6_EXT`_
1123
1124Item: ``IPV6_FRAG_EXT``
1125^^^^^^^^^^^^^^^^^^^^^^^
1126
1127Matches the presence of IPv6 fragment extension header.
1128
1129- ``hdr``: IPv6 fragment extension header definition (``rte_ip.h``).
1130
1131Normally preceded by any of:
1132
1133- `Item: IPV6`_
1134- `Item: IPV6_EXT`_
1135
1136Item: ``IPV6_ROUTING_EXT``
1137^^^^^^^^^^^^^^^^^^^^^^^^^^
1138
1139Matches IPv6 routing extension header.
1140
1141- ``next_hdr``: Next layer header type.
1142- ``type``: IPv6 routing extension header type.
1143- ``segments_left``: How many IPv6 destination addresses carries on.
1144
1145Item: ``ICMP6``
1146^^^^^^^^^^^^^^^
1147
1148Matches any ICMPv6 header.
1149
1150- ``type``: ICMPv6 type.
1151- ``code``: ICMPv6 code.
1152- ``checksum``: ICMPv6 checksum.
1153- Default ``mask`` matches ``type`` and ``code``.
1154
1155Item: ``ICMP6_ECHO_REQUEST``
1156^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1157
1158Matches an ICMPv6 echo request.
1159
1160- ``hdr``: ICMP6 echo header definition (``rte_icmp.h``).
1161
1162Item: ``ICMP6_ECHO_REPLY``
1163^^^^^^^^^^^^^^^^^^^^^^^^^^
1164
1165Matches an ICMPv6 echo reply.
1166
1167- ``hdr``: ICMP6 echo header definition (``rte_icmp.h``).
1168
1169Item: ``ICMP6_ND_NS``
1170^^^^^^^^^^^^^^^^^^^^^
1171
1172Matches an ICMPv6 neighbor discovery solicitation.
1173
1174- ``type``: ICMPv6 type, normally 135.
1175- ``code``: ICMPv6 code, normally 0.
1176- ``checksum``: ICMPv6 checksum.
1177- ``reserved``: reserved, normally 0.
1178- ``target_addr``: target address.
1179- Default ``mask`` matches target address only.
1180
1181Item: ``ICMP6_ND_NA``
1182^^^^^^^^^^^^^^^^^^^^^
1183
1184Matches an ICMPv6 neighbor discovery advertisement.
1185
1186- ``type``: ICMPv6 type, normally 136.
1187- ``code``: ICMPv6 code, normally 0.
1188- ``checksum``: ICMPv6 checksum.
1189- ``rso_reserved``: route flag (1b), solicited flag (1b), override flag
1190  (1b), reserved (29b).
1191- ``target_addr``: target address.
1192- Default ``mask`` matches target address only.
1193
1194Item: ``ICMP6_ND_OPT``
1195^^^^^^^^^^^^^^^^^^^^^^
1196
1197Matches the presence of any ICMPv6 neighbor discovery option.
1198
1199- ``type``: ND option type.
1200- ``length``: ND option length.
1201- Default ``mask`` matches type only.
1202
1203Normally preceded by any of:
1204
1205- `Item: ICMP6_ND_NA`_
1206- `Item: ICMP6_ND_NS`_
1207- `Item: ICMP6_ND_OPT`_
1208
1209Item: ``ICMP6_ND_OPT_SLA_ETH``
1210^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1211
1212Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1213option.
1214
1215- ``type``: ND option type, normally 1.
1216- ``length``: ND option length, normally 1.
1217- ``sla``: source Ethernet LLA.
1218- Default ``mask`` matches source link-layer address only.
1219
1220Normally preceded by any of:
1221
1222- `Item: ICMP6_ND_NA`_
1223- `Item: ICMP6_ND_OPT`_
1224
1225Item: ``ICMP6_ND_OPT_TLA_ETH``
1226^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1227
1228Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1229option.
1230
1231- ``type``: ND option type, normally 2.
1232- ``length``: ND option length, normally 1.
1233- ``tla``: target Ethernet LLA.
1234- Default ``mask`` matches target link-layer address only.
1235
1236Normally preceded by any of:
1237
1238- `Item: ICMP6_ND_NS`_
1239- `Item: ICMP6_ND_OPT`_
1240
1241Item: ``META``
1242^^^^^^^^^^^^^^
1243
1244Matches an application specific 32 bit metadata item.
1245
1246- Default ``mask`` matches the specified metadata value.
1247
1248Item: ``GTP_PSC``
1249^^^^^^^^^^^^^^^^^
1250
1251Matches a GTP PDU extension header with type 0x85.
1252
1253- ``hdr``:  header definition (``rte_gtp.h``).
1254- Default ``mask`` matches QFI only.
1255
1256Item: ``PPPOES``, ``PPPOED``
1257^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1258
1259Matches a PPPoE header.
1260
1261- ``version_type``: version (4b), type (4b).
1262- ``code``: message type.
1263- ``session_id``: session identifier.
1264- ``length``: payload length.
1265
1266Item: ``PPPOE_PROTO_ID``
1267^^^^^^^^^^^^^^^^^^^^^^^^
1268
1269Matches a PPPoE session protocol identifier.
1270
1271- ``proto_id``: PPP protocol identifier.
1272- Default ``mask`` matches proto_id only.
1273
1274Item: ``NSH``
1275^^^^^^^^^^^^^
1276
1277Matches a network service header (RFC 8300).
1278
1279- ``version``: normally 0x0 (2 bits).
1280- ``oam_pkt``: indicate oam packet (1 bit).
1281- ``reserved``: reserved bit (1 bit).
1282- ``ttl``: maximum SFF hopes (6 bits).
1283- ``length``: total length in 4 bytes words (6 bits).
1284- ``reserved1``: reserved1 bits (4 bits).
1285- ``mdtype``: indicates format of NSH header (4 bits).
1286- ``next_proto``: indicates protocol type of encap data (8 bits).
1287- ``spi``: service path identifier (3 bytes).
1288- ``sindex``: service index (1 byte).
1289- Default ``mask`` matches mdtype, next_proto, spi, sindex.
1290
1291
1292Item: ``IGMP``
1293^^^^^^^^^^^^^^
1294
1295Matches a Internet Group Management Protocol (RFC 2236).
1296
1297- ``type``: IGMP message type (Query/Report).
1298- ``max_resp_time``: max time allowed before sending report.
1299- ``checksum``: checksum, 1s complement of whole IGMP message.
1300- ``group_addr``: group address, for Query value will be 0.
1301- Default ``mask`` matches group_addr.
1302
1303
1304Item: ``AH``
1305^^^^^^^^^^^^
1306
1307Matches a IP Authentication Header (RFC 4302).
1308
1309- ``next_hdr``: next payload after AH.
1310- ``payload_len``: total length of AH in 4B words.
1311- ``reserved``: reserved bits.
1312- ``spi``: security parameters index.
1313- ``seq_num``: counter value increased by 1 on each packet sent.
1314- Default ``mask`` matches spi.
1315
1316Item: ``HIGIG2``
1317^^^^^^^^^^^^^^^^^
1318
1319Matches a HIGIG2 header field. It is layer 2.5 protocol and used in
1320Broadcom switches.
1321
1322- Default ``mask`` matches classification and vlan.
1323
1324Item: ``L2TPV3OIP``
1325^^^^^^^^^^^^^^^^^^^
1326
1327Matches a L2TPv3 over IP header.
1328
1329- ``session_id``: L2TPv3 over IP session identifier.
1330- Default ``mask`` matches session_id only.
1331
1332Item: ``PFCP``
1333^^^^^^^^^^^^^^
1334
1335Matches a PFCP Header.
1336
1337- ``s_field``: S field.
1338- ``msg_type``: message type.
1339- ``msg_len``: message length.
1340- ``seid``: session endpoint identifier.
1341- Default ``mask`` matches s_field and seid.
1342
1343Item: ``ECPRI``
1344^^^^^^^^^^^^^^^
1345
1346Matches a eCPRI header.
1347
1348- ``hdr``: eCPRI header definition (``rte_ecpri.h``).
1349- Default ``mask`` matches nothing, for all eCPRI messages.
1350
1351Item: ``PACKET_INTEGRITY_CHECKS``
1352^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1353
1354Matches packet integrity.
1355For some devices application needs to enable integration checks in HW
1356before using this item.
1357
1358- ``level``: the encapsulation level that should be checked:
1359   - ``level == 0`` means the default PMD mode (can be inner most / outermost).
1360   - ``level == 1`` means outermost header.
1361   - ``level > 1``  means inner header. See also RSS level.
1362- ``packet_ok``: All HW packet integrity checks have passed based on the
1363  topmost network layer. For example, for ICMP packet the topmost network
1364  layer is L3 and for TCP or UDP packet the topmost network layer is L4.
1365- ``l2_ok``: all layer 2 HW integrity checks passed.
1366- ``l3_ok``: all layer 3 HW integrity checks passed.
1367- ``l4_ok``: all layer 4 HW integrity checks passed.
1368- ``l2_crc_ok``: layer 2 CRC check passed.
1369- ``ipv4_csum_ok``: IPv4 checksum check passed.
1370- ``l4_csum_ok``: layer 4 checksum check passed.
1371- ``l3_len_ok``: the layer 3 length is smaller than the frame length.
1372
1373Item: ``CONNTRACK``
1374^^^^^^^^^^^^^^^^^^^
1375
1376Matches a conntrack state after conntrack action.
1377
1378- ``flags``: conntrack packet state flags.
1379- Default ``mask`` matches all state bits.
1380
1381Item: ``PORT_REPRESENTOR``
1382^^^^^^^^^^^^^^^^^^^^^^^^^^
1383
1384Matches traffic entering the embedded switch from the given ethdev.
1385
1386Term **ethdev** and the concept of **port representor** are synonymous.
1387The **represented port** is an *entity* plugged to the embedded switch
1388at the opposite end of the "wire" leading to the ethdev.
1389
1390::
1391
1392    .--------------------.
1393    |  PORT_REPRESENTOR  |  Ethdev (Application Port Referred to by its ID)
1394    '--------------------'
1395              ||
1396              \/
1397      .----------------.
1398      |  Logical Port  |
1399      '----------------'
1400              ||
1401              ||
1402              ||
1403              \/
1404         .----------.
1405         |  Switch  |
1406         '----------'
1407              :
1408               :
1409              :
1410               :
1411      .----------------.
1412      |  Logical Port  |
1413      '----------------'
1414              :
1415               :
1416    .--------------------.
1417    |  REPRESENTED_PORT  |  Net / Guest / Another Ethdev (Same Application)
1418    '--------------------'
1419
1420
1421- Incompatible with `Attribute: Traffic direction`_.
1422- Requires `Attribute: Transfer`_.
1423
1424.. _table_rte_flow_item_ethdev:
1425
1426.. table:: ``struct rte_flow_item_ethdev``
1427
1428   +----------+-------------+---------------------------+
1429   | Field    | Subfield    | Value                     |
1430   +==========+=============+===========================+
1431   | ``spec`` | ``port_id`` | ethdev port ID            |
1432   +----------+-------------+---------------------------+
1433   | ``last`` | ``port_id`` | upper range value         |
1434   +----------+-------------+---------------------------+
1435   | ``mask`` | ``port_id`` | zeroed for wildcard match |
1436   +----------+-------------+---------------------------+
1437
1438- Default ``mask`` provides exact match behaviour.
1439
1440See also `Action: PORT_REPRESENTOR`_.
1441
1442Item: ``REPRESENTED_PORT``
1443^^^^^^^^^^^^^^^^^^^^^^^^^^
1444
1445Matches traffic entering the embedded switch from
1446the entity represented by the given ethdev.
1447
1448Term **ethdev** and the concept of **port representor** are synonymous.
1449The **represented port** is an *entity* plugged to the embedded switch
1450at the opposite end of the "wire" leading to the ethdev.
1451
1452::
1453
1454    .--------------------.
1455    |  PORT_REPRESENTOR  |  Ethdev (Application Port Referred to by its ID)
1456    '--------------------'
1457              :
1458               :
1459      .----------------.
1460      |  Logical Port  |
1461      '----------------'
1462              :
1463               :
1464              :
1465               :
1466         .----------.
1467         |  Switch  |
1468         '----------'
1469              /\
1470              ||
1471              ||
1472              ||
1473      .----------------.
1474      |  Logical Port  |
1475      '----------------'
1476              /\
1477              ||
1478    .--------------------.
1479    |  REPRESENTED_PORT  |  Net / Guest / Another Ethdev (Same Application)
1480    '--------------------'
1481
1482
1483- Incompatible with `Attribute: Traffic direction`_.
1484- Requires `Attribute: Transfer`_.
1485
1486This item is meant to use the same structure as `Item: PORT_REPRESENTOR`_.
1487
1488See also `Action: REPRESENTED_PORT`_.
1489
1490Item: ``TX_QUEUE``
1491^^^^^^^^^^^^^^^^^^
1492
1493Matches on the Tx queue of sent packet.
1494
1495- ``tx_queue``: Tx queue.
1496
1497Item: ``AGGR_AFFINITY``
1498^^^^^^^^^^^^^^^^^^^^^^^
1499
1500Matches on the aggregated port of the received packet.
1501In case of multiple aggregated ports, the affinity numbering starts from 1.
1502
1503- ``affinity``: Aggregated affinity.
1504
1505Item: ``FLEX``
1506^^^^^^^^^^^^^^
1507
1508Matches with the custom network protocol header that was created
1509using rte_flow_flex_item_create() API. The application describes
1510the desired header structure, defines the header fields attributes
1511and header relations with preceding and following protocols and
1512configures the ethernet devices accordingly via
1513rte_flow_flex_item_create() routine.
1514
1515- ``handle``: the flex item handle returned by the PMD on successful
1516  rte_flow_flex_item_create() call, mask for this field is ignored.
1517- ``length``: match pattern length in bytes. If the length does not cover
1518  all fields defined in item configuration, the pattern spec and mask are
1519  considered by the driver as padded with trailing zeroes till the full
1520  configured item pattern length.
1521- ``pattern``: pattern to match. The pattern is concatenation of bit fields
1522  configured at item creation. At configuration the fields are presented
1523  by sample_data array. The order of the bitfields is defined by the order
1524  of sample_data elements. The width of each bitfield is defined by the width
1525  specified in the corresponding sample_data element as well. If pattern
1526  length is smaller than configured fields overall length it is considered
1527  as padded with trailing zeroes up to full configured length, both for
1528  value and mask.
1529
1530Item: ``L2TPV2``
1531^^^^^^^^^^^^^^^^
1532
1533Matches a L2TPv2 header.
1534
1535- ``hdr``:  header definition (``rte_l2tpv2.h``).
1536- Default ``mask`` matches flags_version only.
1537
1538Item: ``PPP``
1539^^^^^^^^^^^^^
1540
1541Matches a PPP header.
1542
1543- ``addr``: PPP address.
1544- ``ctrl``: PPP control.
1545- ``proto_id``: PPP protocol identifier.
1546- Default ``mask`` matches addr, ctrl, proto_id.
1547
1548Item: ``METER_COLOR``
1549^^^^^^^^^^^^^^^^^^^^^
1550
1551Matches Color Marker set by a Meter.
1552
1553- ``color``: Metering color marker.
1554
1555Item: ``QUOTA``
1556^^^^^^^^^^^^^^^
1557
1558Matches flow quota state set by quota action.
1559
1560- ``state``: Flow quota state
1561
1562Item: ``IB_BTH``
1563^^^^^^^^^^^^^^^^
1564
1565Matches an InfiniBand base transport header in RoCE packet.
1566
1567- ``hdr``: InfiniBand base transport header definition (``rte_ib.h``).
1568
1569Item: ``PTYPE``
1570^^^^^^^^^^^^^^^
1571
1572Matches the packet type as defined in rte_mbuf_ptype.
1573
1574- ``packet_type``: L2/L3/L4 and tunnel information.
1575
1576Item: ``RANDOM``
1577^^^^^^^^^^^^^^^^
1578
1579Matches a random value.
1580
1581A random unsigned integer (at most 32-bit) is generated for each packet
1582during flow rule processing, by either HW, SW or some external source.
1583Application can match on either exact value or range of values.
1584This value is not based on the packet data/headers.
1585The application shouldn't assume that this value is kept
1586during the lifetime of the packet.
1587
1588- ``value``: Specific value to match.
1589
1590Item: ``COMPARE``
1591^^^^^^^^^^^^^^^^^
1592
1593Matches the comparison result between packet fields or value.
1594
1595- ``compare``: Comparison information.
1596
1597Actions
1598~~~~~~~
1599
1600Each possible action is represented by a type.
1601An action can have an associated configuration object.
1602Several actions combined in a list can be assigned
1603to a flow rule and are performed in order.
1604
1605They fall in three categories:
1606
1607- Actions that modify the fate of matching traffic, for instance by dropping
1608  or assigning it a specific destination.
1609
1610- Actions that modify matching traffic contents or its properties. This
1611  includes adding/removing encapsulation, encryption, compression and marks.
1612
1613- Actions related to the flow rule itself, such as updating counters or
1614  making it non-terminating.
1615
1616Flow rules being terminating by default, not specifying any action of the
1617fate kind results in undefined behavior. This applies to both ingress and
1618egress.
1619
1620PASSTHRU, when supported, makes a flow rule non-terminating.
1621
1622Like matching patterns, action lists are terminated by END items.
1623
1624Example of action that redirects packets to queue index 10:
1625
1626.. _table_rte_flow_action_example:
1627
1628.. table:: Queue action
1629
1630   +-----------+-------+
1631   | Field     | Value |
1632   +===========+=======+
1633   | ``index`` | 10    |
1634   +-----------+-------+
1635
1636Actions are performed in list order:
1637
1638.. _table_rte_flow_count_then_drop:
1639
1640.. table:: Count then drop
1641
1642   +-------+--------+
1643   | Index | Action |
1644   +=======+========+
1645   | 0     | COUNT  |
1646   +-------+--------+
1647   | 1     | DROP   |
1648   +-------+--------+
1649   | 2     | END    |
1650   +-------+--------+
1651
1652|
1653
1654.. _table_rte_flow_mark_count_redirect:
1655
1656.. table:: Mark, count then redirect
1657
1658   +-------+--------+------------+-------+
1659   | Index | Action | Field      | Value |
1660   +=======+========+============+=======+
1661   | 0     | MARK   | ``mark``   | 0x2a  |
1662   +-------+--------+------------+-------+
1663   | 1     | COUNT  | ``id``     | 0     |
1664   +-------+--------+------------+-------+
1665   | 2     | QUEUE  | ``queue``  | 10    |
1666   +-------+--------+------------+-------+
1667   | 3     | END                         |
1668   +-------+-----------------------------+
1669
1670|
1671
1672.. _table_rte_flow_redirect_queue_5:
1673
1674.. table:: Redirect to queue 5
1675
1676   +-------+--------+-----------+-------+
1677   | Index | Action | Field     | Value |
1678   +=======+========+===========+=======+
1679   | 0     | DROP                       |
1680   +-------+--------+-----------+-------+
1681   | 1     | QUEUE  | ``queue`` | 5     |
1682   +-------+--------+-----------+-------+
1683   | 2     | END                        |
1684   +-------+----------------------------+
1685
1686In the above example, while DROP and QUEUE must be performed in order, both
1687have to happen before reaching END. Only QUEUE has a visible effect.
1688
1689Note that such a list may be thought as ambiguous and rejected on that
1690basis.
1691
1692.. _table_rte_flow_redirect_queue_5_3:
1693
1694.. table:: Redirect to queues 5 and 3
1695
1696   +-------+--------+-----------+-------+
1697   | Index | Action | Field     | Value |
1698   +=======+========+===========+=======+
1699   | 0     | QUEUE  | ``queue`` | 5     |
1700   +-------+--------+-----------+-------+
1701   | 1     | VOID                       |
1702   +-------+--------+-----------+-------+
1703   | 2     | QUEUE  | ``queue`` | 3     |
1704   +-------+--------+-----------+-------+
1705   | 3     | END                        |
1706   +-------+----------------------------+
1707
1708As previously described, all actions must be taken into account. This
1709effectively duplicates traffic to both queues. The above example also shows
1710that VOID is ignored.
1711
1712Action types
1713~~~~~~~~~~~~
1714
1715Common action types are described in this section.
1716
1717Action: ``END``
1718^^^^^^^^^^^^^^^
1719
1720End marker for action lists. Prevents further processing of actions, thereby
1721ending the list.
1722
1723- Its numeric value is 0 for convenience.
1724- PMD support is mandatory.
1725- No configurable properties.
1726
1727.. _table_rte_flow_action_end:
1728
1729.. table:: END
1730
1731   +---------------+
1732   | Field         |
1733   +===============+
1734   | no properties |
1735   +---------------+
1736
1737Action: ``VOID``
1738^^^^^^^^^^^^^^^^
1739
1740Used as a placeholder for convenience. It is ignored and simply discarded by
1741PMDs.
1742
1743- PMD support is mandatory.
1744- No configurable properties.
1745
1746.. _table_rte_flow_action_void:
1747
1748.. table:: VOID
1749
1750   +---------------+
1751   | Field         |
1752   +===============+
1753   | no properties |
1754   +---------------+
1755
1756Action: ``PASSTHRU``
1757^^^^^^^^^^^^^^^^^^^^
1758
1759Leaves traffic up for additional processing by subsequent flow rules; makes
1760a flow rule non-terminating.
1761
1762- No configurable properties.
1763
1764.. _table_rte_flow_action_passthru:
1765
1766.. table:: PASSTHRU
1767
1768   +---------------+
1769   | Field         |
1770   +===============+
1771   | no properties |
1772   +---------------+
1773
1774Example to copy a packet to a queue and continue processing by subsequent
1775flow rules:
1776
1777.. _table_rte_flow_action_passthru_example:
1778
1779.. table:: Copy to queue 8
1780
1781   +-------+--------+-----------+-------+
1782   | Index | Action | Field     | Value |
1783   +=======+========+===========+=======+
1784   | 0     | PASSTHRU                   |
1785   +-------+--------+-----------+-------+
1786   | 1     | QUEUE  | ``queue`` | 8     |
1787   +-------+--------+-----------+-------+
1788   | 2     | END                        |
1789   +-------+----------------------------+
1790
1791Action: ``JUMP``
1792^^^^^^^^^^^^^^^^
1793
1794Redirects packets to a group on the current device.
1795
1796In a hierarchy of groups, which can be used to represent physical or logical
1797flow group/tables on the device, this action redirects the matched flow to
1798the specified group on that device.
1799
1800If a matched flow is redirected to a table which doesn't contain a matching
1801rule for that flow, then the behavior is undefined and the resulting behavior
1802is up to the specific device. Best practice when using groups would be to define
1803a default flow rule for each group which a defines the default actions in that
1804group so a consistent behavior is defined.
1805
1806Defining an action for a matched flow in a group to jump to a group which is
1807higher in the group hierarchy may not be supported by physical devices,
1808depending on how groups are mapped to the physical devices. In the
1809definitions of jump actions, applications should be aware that it may be
1810possible to define flow rules which trigger an undefined behavior causing
1811flows to loop between groups.
1812
1813.. _table_rte_flow_action_jump:
1814
1815.. table:: JUMP
1816
1817   +-----------+------------------------------+
1818   | Field     | Value                        |
1819   +===========+==============================+
1820   | ``group`` | Group to redirect packets to |
1821   +-----------+------------------------------+
1822
1823Action: ``JUMP_TO_TABLE_INDEX``
1824^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1825
1826Redirects packets to a particular index in a flow table.
1827
1828Bypassing a hierarchy of groups,
1829this action redirects the matched flow to the specified index
1830in the particular template table on the device.
1831
1832If a matched flow is redirected to a non-existing template table
1833or the table which doesn't contain a rule at the specified index,
1834then the behavior is undefined and the resulting behavior is up to driver.
1835
1836.. _table_rte_flow_action_jump_to_table_index:
1837
1838.. table:: JUMP_TO_TABLE_INDEX
1839
1840   +-----------+-------------------------------------------+
1841   | Field     | Value                                     |
1842   +===========+===========================================+
1843   | ``table`` | Template table to redirect packets to     |
1844   +-----------+-------------------------------------------+
1845   | ``index`` | Index in the table to redirect packets to |
1846   +-----------+-------------------------------------------+
1847
1848Action: ``MARK``
1849^^^^^^^^^^^^^^^^
1850
1851Attaches an integer value to packets and sets ``RTE_MBUF_F_RX_FDIR`` and
1852``RTE_MBUF_F_RX_FDIR_ID`` mbuf flags.
1853
1854This value is arbitrary and application-defined. Maximum allowed value
1855depends on the underlying implementation. It is returned in the
1856``hash.fdir.hi`` mbuf field.
1857
1858.. _table_rte_flow_action_mark:
1859
1860.. table:: MARK
1861
1862   +--------+--------------------------------------+
1863   | Field  | Value                                |
1864   +========+======================================+
1865   | ``id`` | integer value to return with packets |
1866   +--------+--------------------------------------+
1867
1868Action: ``FLAG``
1869^^^^^^^^^^^^^^^^
1870
1871Flags packets. Similar to `Action: MARK`_ without a specific value; only
1872sets the ``RTE_MBUF_F_RX_FDIR`` mbuf flag.
1873
1874- No configurable properties.
1875
1876.. _table_rte_flow_action_flag:
1877
1878.. table:: FLAG
1879
1880   +---------------+
1881   | Field         |
1882   +===============+
1883   | no properties |
1884   +---------------+
1885
1886Action: ``QUEUE``
1887^^^^^^^^^^^^^^^^^
1888
1889Assigns packets to a given queue index.
1890
1891.. _table_rte_flow_action_queue:
1892
1893.. table:: QUEUE
1894
1895   +-----------+--------------------+
1896   | Field     | Value              |
1897   +===========+====================+
1898   | ``index`` | queue index to use |
1899   +-----------+--------------------+
1900
1901Action: ``DROP``
1902^^^^^^^^^^^^^^^^
1903
1904Drop packets.
1905
1906- No configurable properties.
1907
1908.. _table_rte_flow_action_drop:
1909
1910.. table:: DROP
1911
1912   +---------------+
1913   | Field         |
1914   +===============+
1915   | no properties |
1916   +---------------+
1917
1918
1919Action: ``SKIP_CMAN``
1920^^^^^^^^^^^^^^^^^^^^^
1921
1922Skip congestion management on received packets.
1923
1924- Using ``rte_eth_cman_config_set()``,
1925  an application can configure ethdev Rx queue's congestion mechanism.
1926  Once applied, packets congestion configuration is bypassed
1927  on that particular ethdev Rx queue for all packets directed to that queue.
1928
1929.. _table_rte_flow_action_skip_cman:
1930
1931.. table:: SKIP_CMAN
1932
1933   +---------------+
1934   | Field         |
1935   +===============+
1936   | no properties |
1937   +---------------+
1938
1939
1940Action: ``COUNT``
1941^^^^^^^^^^^^^^^^^
1942
1943Adds a counter action to a matched flow.
1944
1945If more than one count action is specified in a single flow rule, then each
1946action must specify a unique id.
1947
1948Counters can be retrieved and reset through ``rte_flow_query()``, see
1949``struct rte_flow_query_count``.
1950
1951For ports within the same switch domain then the counter id namespace extends
1952to all ports within that switch domain.
1953
1954.. _table_rte_flow_action_count:
1955
1956.. table:: COUNT
1957
1958   +------------+---------------------------------+
1959   | Field      | Value                           |
1960   +============+=================================+
1961   | ``id``     | counter id                      |
1962   +------------+---------------------------------+
1963
1964Query structure to retrieve and reset flow rule counters:
1965
1966.. _table_rte_flow_query_count:
1967
1968.. table:: COUNT query
1969
1970   +---------------+-----+-----------------------------------+
1971   | Field         | I/O | Value                             |
1972   +===============+=====+===================================+
1973   | ``reset``     | in  | reset counter after query         |
1974   +---------------+-----+-----------------------------------+
1975   | ``hits_set``  | out | ``hits`` field is set             |
1976   +---------------+-----+-----------------------------------+
1977   | ``bytes_set`` | out | ``bytes`` field is set            |
1978   +---------------+-----+-----------------------------------+
1979   | ``hits``      | out | number of hits for this rule      |
1980   +---------------+-----+-----------------------------------+
1981   | ``bytes``     | out | number of bytes through this rule |
1982   +---------------+-----+-----------------------------------+
1983
1984Action: ``RSS``
1985^^^^^^^^^^^^^^^
1986
1987Similar to QUEUE, except RSS is additionally performed on packets to spread
1988them among several queues according to the provided parameters.
1989
1990Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1991field does not disable RSS in a flow rule. Doing so instead requests safe
1992unspecified "best-effort" settings from the underlying PMD, which depending
1993on the flow rule, may result in anything ranging from empty (single queue)
1994to all-inclusive RSS.
1995
1996If non-applicable for matching packets RSS types are requested,
1997these RSS types are simply ignored. For example, it happens if:
1998
1999- Hashing of both TCP and UDP ports is requested
2000  (only one can be present in a packet).
2001
2002- Requested RSS types contradict to flow rule pattern
2003  (e.g. pattern has UDP item, but RSS types contain TCP).
2004
2005If requested RSS hash types are not supported by the Ethernet device at all
2006(not reported in ``dev_info.flow_type_rss_offloads``),
2007the flow creation will fail.
2008
2009Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
2010overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
2011field only, both can be requested simultaneously.
2012
2013Also, regarding packet encapsulation ``level``:
2014
2015- ``0`` requests the default behavior. Depending on the packet type, it can
2016  mean outermost, innermost, anything in between or even no RSS.
2017
2018  It basically stands for the innermost encapsulation level RSS can be
2019  performed on according to PMD and device capabilities.
2020
2021- ``1`` requests RSS to be performed on the outermost packet encapsulation
2022  level.
2023
2024- ``2`` and subsequent values request RSS to be performed on the specified
2025  inner packet encapsulation level, from outermost to innermost (lower to
2026  higher values).
2027
2028Values other than ``0`` are not necessarily supported.
2029
2030Requesting a specific RSS level on unrecognized traffic results in undefined
2031behavior. For predictable results, it is recommended to make the flow rule
2032pattern match packet headers up to the requested encapsulation level so that
2033only matching traffic goes through.
2034
2035.. _table_rte_flow_action_rss:
2036
2037.. table:: RSS
2038
2039   +---------------+-------------------------------------------------+
2040   | Field         | Value                                           |
2041   +===============+=================================================+
2042   | ``func``      | RSS hash function to apply                      |
2043   +---------------+-------------------------------------------------+
2044   | ``level``     | encapsulation level for ``types``               |
2045   +---------------+-------------------------------------------------+
2046   | ``types``     | specific RSS hash types (see ``RTE_ETH_RSS_*``) |
2047   +---------------+-------------------------------------------------+
2048   | ``key_len``   | hash key length in bytes                        |
2049   +---------------+-------------------------------------------------+
2050   | ``queue_num`` | number of entries in ``queue``                  |
2051   +---------------+-------------------------------------------------+
2052   | ``key``       | hash key                                        |
2053   +---------------+-------------------------------------------------+
2054   | ``queue``     | queue indices to use                            |
2055   +---------------+-------------------------------------------------+
2056
2057Action: ``PF``
2058^^^^^^^^^^^^^^
2059
2060This action is deprecated. Consider:
2061 - `Action: PORT_REPRESENTOR`_
2062 - `Action: REPRESENTED_PORT`_
2063
2064Directs matching traffic to the physical function (PF) of the current
2065device.
2066
2067- No configurable properties.
2068
2069.. _table_rte_flow_action_pf:
2070
2071.. table:: PF
2072
2073   +---------------+
2074   | Field         |
2075   +===============+
2076   | no properties |
2077   +---------------+
2078
2079Action: ``VF``
2080^^^^^^^^^^^^^^
2081
2082This action is deprecated. Consider:
2083 - `Action: PORT_REPRESENTOR`_
2084 - `Action: REPRESENTED_PORT`_
2085
2086Directs matching traffic to a given virtual function of the current device.
2087
2088Packets can be redirected to the VF they originate from,
2089instead of the specified one. This parameter may not be available and is
2090not guaranteed to work properly if the VF part is matched by a prior flow
2091rule or if packets are not addressed to a VF in the first place.
2092
2093.. _table_rte_flow_action_vf:
2094
2095.. table:: VF
2096
2097   +--------------+--------------------------------+
2098   | Field        | Value                          |
2099   +==============+================================+
2100   | ``original`` | use original VF ID if possible |
2101   +--------------+--------------------------------+
2102   | ``id``       | VF ID                          |
2103   +--------------+--------------------------------+
2104
2105Action: ``PORT_ID``
2106^^^^^^^^^^^^^^^^^^^
2107This action is deprecated. Consider:
2108 - `Action: PORT_REPRESENTOR`_
2109 - `Action: REPRESENTED_PORT`_
2110
2111Directs matching traffic to a given DPDK port ID.
2112
2113See `Item: PORT_ID`_.
2114
2115.. _table_rte_flow_action_port_id:
2116
2117.. table:: PORT_ID
2118
2119   +--------------+---------------------------------------+
2120   | Field        | Value                                 |
2121   +==============+=======================================+
2122   | ``original`` | use original DPDK port ID if possible |
2123   +--------------+---------------------------------------+
2124   | ``id``       | DPDK port ID                          |
2125   +--------------+---------------------------------------+
2126
2127Action: ``METER``
2128^^^^^^^^^^^^^^^^^
2129
2130Applies a stage of metering and policing.
2131
2132The metering and policing (MTR) object has to be first created using the
2133rte_mtr_create() API function. The ID of the MTR object is specified as
2134action parameter. More than one flow can use the same MTR object through
2135the meter action. The MTR object can be further updated or queried using
2136the rte_mtr* API.
2137
2138.. _table_rte_flow_action_meter:
2139
2140.. table:: METER
2141
2142   +--------------+---------------+
2143   | Field        | Value         |
2144   +==============+===============+
2145   | ``mtr_id``   | MTR object ID |
2146   +--------------+---------------+
2147
2148Action: ``SECURITY``
2149^^^^^^^^^^^^^^^^^^^^
2150
2151Perform the security action on flows matched by the pattern items
2152according to the configuration of the security session.
2153
2154This action modifies the payload of matched flows. For INLINE_CRYPTO, the
2155security protocol headers and IV are fully provided by the application as
2156specified in the flow pattern. The payload of matching packets is
2157encrypted on egress, and decrypted and authenticated on ingress.
2158For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
2159providing full encapsulation and decapsulation of packets in security
2160protocols. The flow pattern specifies both the outer security header fields
2161and the inner packet fields. The security session specified in the action
2162must match the pattern parameters.
2163
2164The security session specified in the action must be created on the same
2165port as the flow action that is being specified.
2166
2167The ingress/egress flow attribute should match that specified in the
2168security session if the security session supports the definition of the
2169direction.
2170
2171Multiple flows can be configured to use the same security session.
2172
2173.. _table_rte_flow_action_security:
2174
2175.. table:: SECURITY
2176
2177   +----------------------+--------------------------------------+
2178   | Field                | Value                                |
2179   +======================+======================================+
2180   | ``security_session`` | security session to apply            |
2181   +----------------------+--------------------------------------+
2182
2183The following is an example of configuring IPsec inline using the
2184INLINE_CRYPTO security session:
2185
2186The encryption algorithm, keys and salt are part of the opaque
2187``rte_security_session``. The SA is identified according to the IP and ESP
2188fields in the pattern items.
2189
2190.. _table_rte_flow_item_esp_inline_example:
2191
2192.. table:: IPsec inline crypto flow pattern items.
2193
2194   +-------+----------+
2195   | Index | Item     |
2196   +=======+==========+
2197   | 0     | Ethernet |
2198   +-------+----------+
2199   | 1     | IPv4     |
2200   +-------+----------+
2201   | 2     | ESP      |
2202   +-------+----------+
2203   | 3     | END      |
2204   +-------+----------+
2205
2206.. _table_rte_flow_action_esp_inline_example:
2207
2208.. table:: IPsec inline flow actions.
2209
2210   +-------+----------+
2211   | Index | Action   |
2212   +=======+==========+
2213   | 0     | SECURITY |
2214   +-------+----------+
2215   | 1     | END      |
2216   +-------+----------+
2217
2218Action: ``OF_DEC_NW_TTL``
2219^^^^^^^^^^^^^^^^^^^^^^^^^
2220This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2221
2222Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the
2223`OpenFlow Switch Specification`_.
2224
2225.. _table_rte_flow_action_of_dec_nw_ttl:
2226
2227.. table:: OF_DEC_NW_TTL
2228
2229   +---------------+
2230   | Field         |
2231   +===============+
2232   | no properties |
2233   +---------------+
2234
2235Action: ``OF_POP_VLAN``
2236^^^^^^^^^^^^^^^^^^^^^^^
2237
2238Implements ``OFPAT_POP_VLAN`` ("pop the outer VLAN tag") as defined
2239by the `OpenFlow Switch Specification`_.
2240
2241.. _table_rte_flow_action_of_pop_vlan:
2242
2243.. table:: OF_POP_VLAN
2244
2245   +---------------+
2246   | Field         |
2247   +===============+
2248   | no properties |
2249   +---------------+
2250
2251Action: ``OF_PUSH_VLAN``
2252^^^^^^^^^^^^^^^^^^^^^^^^
2253
2254Implements ``OFPAT_PUSH_VLAN`` ("push a new VLAN tag") as defined by the
2255`OpenFlow Switch Specification`_.
2256
2257.. _table_rte_flow_action_of_push_vlan:
2258
2259.. table:: OF_PUSH_VLAN
2260
2261   +---------------+-----------+
2262   | Field         | Value     |
2263   +===============+===========+
2264   | ``ethertype`` | EtherType |
2265   +---------------+-----------+
2266
2267Action: ``OF_SET_VLAN_VID``
2268^^^^^^^^^^^^^^^^^^^^^^^^^^^
2269
2270Implements ``OFPAT_SET_VLAN_VID`` ("set the 802.1q VLAN id") as defined by
2271the `OpenFlow Switch Specification`_.
2272
2273.. _table_rte_flow_action_of_set_vlan_vid:
2274
2275.. table:: OF_SET_VLAN_VID
2276
2277   +--------------+---------+
2278   | Field        | Value   |
2279   +==============+=========+
2280   | ``vlan_vid`` | VLAN id |
2281   +--------------+---------+
2282
2283Action: ``OF_SET_VLAN_PCP``
2284^^^^^^^^^^^^^^^^^^^^^^^^^^^
2285
2286Implements ``OFPAT_SET_LAN_PCP`` ("set the 802.1q priority") as defined by
2287the `OpenFlow Switch Specification`_.
2288
2289.. _table_rte_flow_action_of_set_vlan_pcp:
2290
2291.. table:: OF_SET_VLAN_PCP
2292
2293   +--------------+---------------+
2294   | Field        | Value         |
2295   +==============+===============+
2296   | ``vlan_pcp`` | VLAN priority |
2297   +--------------+---------------+
2298
2299Action: ``OF_POP_MPLS``
2300^^^^^^^^^^^^^^^^^^^^^^^
2301
2302Implements ``OFPAT_POP_MPLS`` ("pop the outer MPLS tag") as defined by the
2303`OpenFlow Switch Specification`_.
2304
2305.. _table_rte_flow_action_of_pop_mpls:
2306
2307.. table:: OF_POP_MPLS
2308
2309   +---------------+-----------+
2310   | Field         | Value     |
2311   +===============+===========+
2312   | ``ethertype`` | EtherType |
2313   +---------------+-----------+
2314
2315Action: ``OF_PUSH_MPLS``
2316^^^^^^^^^^^^^^^^^^^^^^^^
2317
2318Implements ``OFPAT_PUSH_MPLS`` ("push a new MPLS tag") as defined by the
2319`OpenFlow Switch Specification`_.
2320
2321.. _table_rte_flow_action_of_push_mpls:
2322
2323.. table:: OF_PUSH_MPLS
2324
2325   +---------------+-----------+
2326   | Field         | Value     |
2327   +===============+===========+
2328   | ``ethertype`` | EtherType |
2329   +---------------+-----------+
2330
2331Action: ``VXLAN_ENCAP``
2332^^^^^^^^^^^^^^^^^^^^^^^
2333
2334Performs a VXLAN encapsulation action by encapsulating the matched flow in the
2335VXLAN tunnel as defined in the``rte_flow_action_vxlan_encap`` flow items
2336definition.
2337
2338This action modifies the payload of matched flows. The flow definition specified
2339in the ``rte_flow_action_tunnel_encap`` action structure must define a valid
2340VLXAN network overlay which conforms with RFC 7348 (Virtual eXtensible Local
2341Area Network (VXLAN): A Framework for Overlaying Virtualized Layer 2 Networks
2342over Layer 3 Networks). The pattern must be terminated with the
2343RTE_FLOW_ITEM_TYPE_END item type.
2344
2345.. _table_rte_flow_action_vxlan_encap:
2346
2347.. table:: VXLAN_ENCAP
2348
2349   +----------------+-------------------------------------+
2350   | Field          | Value                               |
2351   +================+=====================================+
2352   | ``definition`` | Tunnel end-point overlay definition |
2353   +----------------+-------------------------------------+
2354
2355.. _table_rte_flow_action_vxlan_encap_example:
2356
2357.. table:: IPv4 VxLAN flow pattern example.
2358
2359   +-------+----------+
2360   | Index | Item     |
2361   +=======+==========+
2362   | 0     | Ethernet |
2363   +-------+----------+
2364   | 1     | IPv4     |
2365   +-------+----------+
2366   | 2     | UDP      |
2367   +-------+----------+
2368   | 3     | VXLAN    |
2369   +-------+----------+
2370   | 4     | END      |
2371   +-------+----------+
2372
2373Action: ``VXLAN_DECAP``
2374^^^^^^^^^^^^^^^^^^^^^^^
2375
2376Performs a decapsulation action by stripping all headers of the VXLAN tunnel
2377network overlay from the matched flow.
2378
2379The flow items pattern defined for the flow rule with which a ``VXLAN_DECAP``
2380action is specified, must define a valid VXLAN tunnel as per RFC7348. If the
2381flow pattern does not specify a valid VXLAN tunnel then a
2382RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2383
2384This action modifies the payload of matched flows.
2385
2386Action: ``NVGRE_ENCAP``
2387^^^^^^^^^^^^^^^^^^^^^^^
2388
2389Performs a NVGRE encapsulation action by encapsulating the matched flow in the
2390NVGRE tunnel as defined in the``rte_flow_action_tunnel_encap`` flow item
2391definition.
2392
2393This action modifies the payload of matched flows. The flow definition specified
2394in the ``rte_flow_action_tunnel_encap`` action structure must defined a valid
2395NVGRE network overlay which conforms with RFC 7637 (NVGRE: Network
2396Virtualization Using Generic Routing Encapsulation). The pattern must be
2397terminated with the RTE_FLOW_ITEM_TYPE_END item type.
2398
2399.. _table_rte_flow_action_nvgre_encap:
2400
2401.. table:: NVGRE_ENCAP
2402
2403   +----------------+-------------------------------------+
2404   | Field          | Value                               |
2405   +================+=====================================+
2406   | ``definition`` | NVGRE end-point overlay definition  |
2407   +----------------+-------------------------------------+
2408
2409.. _table_rte_flow_action_nvgre_encap_example:
2410
2411.. table:: IPv4 NVGRE flow pattern example.
2412
2413   +-------+----------+
2414   | Index | Item     |
2415   +=======+==========+
2416   | 0     | Ethernet |
2417   +-------+----------+
2418   | 1     | IPv4     |
2419   +-------+----------+
2420   | 2     | NVGRE    |
2421   +-------+----------+
2422   | 3     | END      |
2423   +-------+----------+
2424
2425Action: ``NVGRE_DECAP``
2426^^^^^^^^^^^^^^^^^^^^^^^
2427
2428Performs a decapsulation action by stripping all headers of the NVGRE tunnel
2429network overlay from the matched flow.
2430
2431The flow items pattern defined for the flow rule with which a ``NVGRE_DECAP``
2432action is specified, must define a valid NVGRE tunnel as per RFC7637. If the
2433flow pattern does not specify a valid NVGRE tunnel then a
2434RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2435
2436This action modifies the payload of matched flows.
2437
2438Action: ``RAW_ENCAP``
2439^^^^^^^^^^^^^^^^^^^^^
2440
2441Adds outer header whose template is provided in its data buffer,
2442as defined in the ``rte_flow_action_raw_encap`` definition.
2443
2444This action modifies the payload of matched flows. The data supplied must
2445be a valid header, either holding layer 2 data in case of adding layer 2 after
2446decap layer 3 tunnel (for example MPLSoGRE) or complete tunnel definition
2447starting from layer 2 and moving to the tunnel item itself. When applied to
2448the original packet the resulting packet must be a valid packet.
2449
2450.. _table_rte_flow_action_raw_encap:
2451
2452.. table:: RAW_ENCAP
2453
2454   +----------------+----------------------------------------+
2455   | Field          | Value                                  |
2456   +================+========================================+
2457   | ``data``       | Encapsulation data                     |
2458   +----------------+----------------------------------------+
2459   | ``preserve``   | Bit-mask of data to preserve on output |
2460   +----------------+----------------------------------------+
2461   | ``size``       | Size of data and preserve              |
2462   +----------------+----------------------------------------+
2463
2464Action: ``RAW_DECAP``
2465^^^^^^^^^^^^^^^^^^^^^^^
2466
2467Remove outer header whose template is provided in its data buffer,
2468as defined in the ``rte_flow_action_raw_decap``
2469
2470This action modifies the payload of matched flows. The data supplied must
2471be a valid header, either holding layer 2 data in case of removing layer 2
2472before encapsulation of layer 3 tunnel (for example MPLSoGRE) or complete
2473tunnel definition starting from layer 2 and moving to the tunnel item itself.
2474When applied to the original packet the resulting packet must be a
2475valid packet.
2476
2477.. _table_rte_flow_action_raw_decap:
2478
2479.. table:: RAW_DECAP
2480
2481   +----------------+----------------------------------------+
2482   | Field          | Value                                  |
2483   +================+========================================+
2484   | ``data``       | Decapsulation data                     |
2485   +----------------+----------------------------------------+
2486   | ``size``       | Size of data                           |
2487   +----------------+----------------------------------------+
2488
2489Action: ``SET_IPV4_SRC``
2490^^^^^^^^^^^^^^^^^^^^^^^^
2491This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2492
2493Set a new IPv4 source address in the outermost IPv4 header.
2494
2495It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2496Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2497
2498.. _table_rte_flow_action_set_ipv4_src:
2499
2500.. table:: SET_IPV4_SRC
2501
2502   +-----------------------------------------+
2503   | Field         | Value                   |
2504   +===============+=========================+
2505   | ``ipv4_addr`` | new IPv4 source address |
2506   +---------------+-------------------------+
2507
2508Action: ``SET_IPV4_DST``
2509^^^^^^^^^^^^^^^^^^^^^^^^
2510This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2511
2512Set a new IPv4 destination address in the outermost IPv4 header.
2513
2514It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2515Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2516
2517.. _table_rte_flow_action_set_ipv4_dst:
2518
2519.. table:: SET_IPV4_DST
2520
2521   +---------------+------------------------------+
2522   | Field         | Value                        |
2523   +===============+==============================+
2524   | ``ipv4_addr`` | new IPv4 destination address |
2525   +---------------+------------------------------+
2526
2527Action: ``SET_IPV6_SRC``
2528^^^^^^^^^^^^^^^^^^^^^^^^
2529This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2530
2531Set a new IPv6 source address in the outermost IPv6 header.
2532
2533It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2534Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2535
2536.. _table_rte_flow_action_set_ipv6_src:
2537
2538.. table:: SET_IPV6_SRC
2539
2540   +---------------+-------------------------+
2541   | Field         | Value                   |
2542   +===============+=========================+
2543   | ``ipv6_addr`` | new IPv6 source address |
2544   +---------------+-------------------------+
2545
2546Action: ``SET_IPV6_DST``
2547^^^^^^^^^^^^^^^^^^^^^^^^
2548This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2549
2550Set a new IPv6 destination address in the outermost IPv6 header.
2551
2552It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2553Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2554
2555.. _table_rte_flow_action_set_ipv6_dst:
2556
2557.. table:: SET_IPV6_DST
2558
2559   +---------------+------------------------------+
2560   | Field         | Value                        |
2561   +===============+==============================+
2562   | ``ipv6_addr`` | new IPv6 destination address |
2563   +---------------+------------------------------+
2564
2565Action: ``IPV6_EXT_PUSH``
2566^^^^^^^^^^^^^^^^^^^^^^^^^
2567
2568Add an IPv6 extension into IPv6 header.
2569Its template is provided in its data buffer
2570with the specific type as defined in ``rte_flow_action_ipv6_ext_push``.
2571
2572This action modifies the payload of matched flows.
2573The data supplied must be a valid extension in the specified type,
2574it should be added the last one if preceding extension existed.
2575When applied to the original packet,
2576the resulting packet must be a valid packet.
2577
2578Action: ``IPV6_EXT_REMOVE``
2579^^^^^^^^^^^^^^^^^^^^^^^^^^^
2580
2581Remove an IPv6 extension whose type is provided in
2582``rte_flow_action_ipv6_ext_remove``.
2583
2584This action modifies the payload of matched flow
2585and the packet should be valid after removing.
2586
2587Action: ``SET_TP_SRC``
2588^^^^^^^^^^^^^^^^^^^^^^^^^
2589This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2590
2591Set a new source port number in the outermost TCP/UDP header.
2592
2593It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2594flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2595
2596.. _table_rte_flow_action_set_tp_src:
2597
2598.. table:: SET_TP_SRC
2599
2600   +----------+-------------------------+
2601   | Field    | Value                   |
2602   +==========+=========================+
2603   | ``port`` | new TCP/UDP source port |
2604   +---------------+--------------------+
2605
2606Action: ``SET_TP_DST``
2607^^^^^^^^^^^^^^^^^^^^^^^^^
2608This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2609
2610Set a new destination port number in the outermost TCP/UDP header.
2611
2612It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2613flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2614
2615.. _table_rte_flow_action_set_tp_dst:
2616
2617.. table:: SET_TP_DST
2618
2619   +----------+------------------------------+
2620   | Field    | Value                        |
2621   +==========+==============================+
2622   | ``port`` | new TCP/UDP destination port |
2623   +---------------+-------------------------+
2624
2625Action: ``MAC_SWAP``
2626^^^^^^^^^^^^^^^^^^^^^^^^^
2627
2628Swap the source and destination MAC addresses in the outermost Ethernet
2629header.
2630
2631It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2632Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2633
2634.. _table_rte_flow_action_mac_swap:
2635
2636.. table:: MAC_SWAP
2637
2638   +---------------+
2639   | Field         |
2640   +===============+
2641   | no properties |
2642   +---------------+
2643
2644Action: ``DEC_TTL``
2645^^^^^^^^^^^^^^^^^^^
2646This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2647
2648Decrease TTL value.
2649
2650If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2651in pattern, Some PMDs will reject rule because behavior will be undefined.
2652
2653.. _table_rte_flow_action_dec_ttl:
2654
2655.. table:: DEC_TTL
2656
2657   +---------------+
2658   | Field         |
2659   +===============+
2660   | no properties |
2661   +---------------+
2662
2663Action: ``SET_TTL``
2664^^^^^^^^^^^^^^^^^^^
2665This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2666
2667Assigns a new TTL value.
2668
2669If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2670in pattern, Some PMDs will reject rule because behavior will be undefined.
2671
2672.. _table_rte_flow_action_set_ttl:
2673
2674.. table:: SET_TTL
2675
2676   +---------------+--------------------+
2677   | Field         | Value              |
2678   +===============+====================+
2679   | ``ttl_value`` | new TTL value      |
2680   +---------------+--------------------+
2681
2682Action: ``SET_MAC_SRC``
2683^^^^^^^^^^^^^^^^^^^^^^^
2684This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2685
2686Set source MAC address.
2687
2688It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2689Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2690
2691.. _table_rte_flow_action_set_mac_src:
2692
2693.. table:: SET_MAC_SRC
2694
2695   +--------------+---------------+
2696   | Field        | Value         |
2697   +==============+===============+
2698   | ``mac_addr`` | MAC address   |
2699   +--------------+---------------+
2700
2701Action: ``SET_MAC_DST``
2702^^^^^^^^^^^^^^^^^^^^^^^
2703This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2704
2705Set destination MAC address.
2706
2707It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2708Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2709
2710.. _table_rte_flow_action_set_mac_dst:
2711
2712.. table:: SET_MAC_DST
2713
2714   +--------------+---------------+
2715   | Field        | Value         |
2716   +==============+===============+
2717   | ``mac_addr`` | MAC address   |
2718   +--------------+---------------+
2719
2720Action: ``INC_TCP_SEQ``
2721^^^^^^^^^^^^^^^^^^^^^^^
2722This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2723
2724Increase sequence number in the outermost TCP header.
2725Value to increase TCP sequence number by is a big-endian 32 bit integer.
2726
2727Using this action on non-matching traffic will result in undefined behavior.
2728
2729Action: ``DEC_TCP_SEQ``
2730^^^^^^^^^^^^^^^^^^^^^^^
2731This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2732
2733Decrease sequence number in the outermost TCP header.
2734Value to decrease TCP sequence number by is a big-endian 32 bit integer.
2735
2736Using this action on non-matching traffic will result in undefined behavior.
2737
2738Action: ``INC_TCP_ACK``
2739^^^^^^^^^^^^^^^^^^^^^^^
2740This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2741
2742Increase acknowledgment number in the outermost TCP header.
2743Value to increase TCP acknowledgment number by is a big-endian 32 bit integer.
2744
2745Using this action on non-matching traffic will result in undefined behavior.
2746
2747Action: ``DEC_TCP_ACK``
2748^^^^^^^^^^^^^^^^^^^^^^^
2749This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2750
2751Decrease acknowledgment number in the outermost TCP header.
2752Value to decrease TCP acknowledgment number by is a big-endian 32 bit integer.
2753
2754Using this action on non-matching traffic will result in undefined behavior.
2755
2756Action: ``SET_TAG``
2757^^^^^^^^^^^^^^^^^^^
2758This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2759
2760Set Tag.
2761
2762Tag is a transient data used during flow matching. This is not delivered to
2763application. Multiple tags are supported by specifying index.
2764
2765.. _table_rte_flow_action_set_tag:
2766
2767.. table:: SET_TAG
2768
2769   +-----------+----------------------------+
2770   | Field     | Value                      |
2771   +===========+============================+
2772   | ``data``  | 32 bit tag value           |
2773   +-----------+----------------------------+
2774   | ``mask``  | bit-mask applies to "data" |
2775   +-----------+----------------------------+
2776   | ``index`` | index of tag to set        |
2777   +-----------+----------------------------+
2778
2779Action: ``SET_META``
2780^^^^^^^^^^^^^^^^^^^^^^^
2781This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2782
2783Set metadata. Item ``META`` matches metadata.
2784
2785Metadata set by mbuf metadata field with RTE_MBUF_DYNFLAG_TX_METADATA flag on egress
2786will be overridden by this action. On ingress, the metadata will be carried by
2787``metadata`` dynamic field of ``rte_mbuf`` which can be accessed by
2788``RTE_FLOW_DYNF_METADATA()``. RTE_MBUF_DYNFLAG_RX_METADATA flag will be set along
2789with the data.
2790
2791The mbuf dynamic field must be registered by calling
2792``rte_flow_dynf_metadata_register()`` prior to use ``SET_META`` action.
2793
2794Altering partial bits is supported with ``mask``. For bits which have never been
2795set, unpredictable value will be seen depending on driver implementation. For
2796loopback/hairpin packet, metadata set on Rx/Tx may or may not be propagated to
2797the other path depending on HW capability.
2798
2799In hairpin case with Tx explicit flow mode, metadata could (not mandatory) be
2800used to connect the Rx and Tx flows if it can be propagated from Rx to Tx path.
2801
2802.. _table_rte_flow_action_set_meta:
2803
2804.. table:: SET_META
2805
2806   +----------+----------------------------+
2807   | Field    | Value                      |
2808   +==========+============================+
2809   | ``data`` | 32 bit metadata value      |
2810   +----------+----------------------------+
2811   | ``mask`` | bit-mask applies to "data" |
2812   +----------+----------------------------+
2813
2814Action: ``SET_IPV4_DSCP``
2815^^^^^^^^^^^^^^^^^^^^^^^^^
2816This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2817
2818Set IPv4 DSCP.
2819
2820Modify DSCP in IPv4 header.
2821
2822It must be used with RTE_FLOW_ITEM_TYPE_IPV4 in pattern.
2823Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2824
2825.. _table_rte_flow_action_set_ipv4_dscp:
2826
2827.. table:: SET_IPV4_DSCP
2828
2829   +-----------+---------------------------------+
2830   | Field     | Value                           |
2831   +===========+=================================+
2832   | ``dscp``  | DSCP in low 6 bits, rest ignore |
2833   +-----------+---------------------------------+
2834
2835Action: ``SET_IPV6_DSCP``
2836^^^^^^^^^^^^^^^^^^^^^^^^^
2837This is a legacy action. Consider `Action: MODIFY_FIELD`_ as alternative.
2838
2839Set IPv6 DSCP.
2840
2841Modify DSCP in IPv6 header.
2842
2843It must be used with RTE_FLOW_ITEM_TYPE_IPV6 in pattern.
2844Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2845
2846.. _table_rte_flow_action_set_ipv6_dscp:
2847
2848.. table:: SET_IPV6_DSCP
2849
2850   +-----------+---------------------------------+
2851   | Field     | Value                           |
2852   +===========+=================================+
2853   | ``dscp``  | DSCP in low 6 bits, rest ignore |
2854   +-----------+---------------------------------+
2855
2856Action: ``NAT64``
2857^^^^^^^^^^^^^^^^^
2858
2859This action does header translation between IPv4 and IPv6.
2860Besides converting the IP addresses,
2861other fields in the IP header are handled as well.
2862The ``type`` field should be provided
2863as defined in ``rte_flow_action_nat64`` when creating the action.
2864
2865Action: ``AGE``
2866^^^^^^^^^^^^^^^
2867
2868Set ageing timeout configuration to a flow.
2869
2870Event RTE_ETH_EVENT_FLOW_AGED will be reported if
2871timeout passed without any matching on the flow.
2872
2873.. _table_rte_flow_action_age:
2874
2875.. table:: AGE
2876
2877   +--------------+---------------------------------+
2878   | Field        | Value                           |
2879   +==============+=================================+
2880   | ``timeout``  | 24 bits timeout value           |
2881   +--------------+---------------------------------+
2882   | ``reserved`` | 8 bits reserved, must be zero   |
2883   +--------------+---------------------------------+
2884   | ``context``  | user input flow context         |
2885   +--------------+---------------------------------+
2886
2887Query structure to retrieve ageing status information of a
2888shared AGE action, or a flow rule using the AGE action:
2889
2890.. _table_rte_flow_query_age:
2891
2892.. table:: AGE query
2893
2894   +------------------------------+-----+----------------------------------------+
2895   | Field                        | I/O | Value                                  |
2896   +==============================+=====+========================================+
2897   | ``aged``                     | out | Aging timeout expired                  |
2898   +------------------------------+-----+----------------------------------------+
2899   | ``sec_since_last_hit_valid`` | out | ``sec_since_last_hit`` value is valid  |
2900   +------------------------------+-----+----------------------------------------+
2901   | ``sec_since_last_hit``       | out | Seconds since last traffic hit         |
2902   +------------------------------+-----+----------------------------------------+
2903
2904Update structure to modify the parameters of an indirect AGE action.
2905The update structure is used by ``rte_flow_action_handle_update()`` function.
2906
2907.. _table_rte_flow_update_age:
2908
2909.. table:: AGE update
2910
2911   +-------------------+--------------------------------------------------------------+
2912   | Field             | Value                                                        |
2913   +===================+==============================================================+
2914   | ``reserved``      | 6 bits reserved, must be zero                                |
2915   +-------------------+--------------------------------------------------------------+
2916   | ``timeout_valid`` | 1 bit, timeout value is valid                                |
2917   +-------------------+--------------------------------------------------------------+
2918   | ``timeout``       | 24 bits timeout value                                        |
2919   +-------------------+--------------------------------------------------------------+
2920   | ``touch``         | 1 bit, touch the AGE action to set ``sec_since_last_hit`` 0  |
2921   +-------------------+--------------------------------------------------------------+
2922
2923Action: ``SAMPLE``
2924^^^^^^^^^^^^^^^^^^
2925
2926Adds a sample action to a matched flow.
2927
2928The matching packets will be duplicated with the specified ``ratio`` and
2929applied with own set of actions with a fate action, the packets sampled
2930equals is '1/ratio'. All the packets continue to the target destination.
2931
2932When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
2933``actions`` represent the different set of actions for the sampled or mirrored
2934packets, and must have a fate action.
2935
2936.. _table_rte_flow_action_sample:
2937
2938.. table:: SAMPLE
2939
2940   +--------------+---------------------------------+
2941   | Field        | Value                           |
2942   +==============+=================================+
2943   | ``ratio``    | 32 bits sample ratio value      |
2944   +--------------+---------------------------------+
2945   | ``actions``  | sub-action list for sampling    |
2946   +--------------+---------------------------------+
2947
2948Action: ``INDIRECT``
2949^^^^^^^^^^^^^^^^^^^^
2950
2951Flow utilize indirect action by handle as returned from
2952``rte_flow_action_handle_create()``.
2953
2954The behaviour of the indirect action defined by ``action`` argument of type
2955``struct rte_flow_action`` passed to ``rte_flow_action_handle_create()``.
2956
2957The indirect action can be used by a single flow or shared among multiple flows.
2958The indirect action can be in-place updated by ``rte_flow_action_handle_update()``
2959without destroying flow and creating flow again. The fields that could be
2960updated depend on the type of the ``action`` and different for every type.
2961
2962The indirect action specified data (e.g. counter) can be queried by
2963``rte_flow_action_handle_query()``.
2964
2965.. warning::
2966
2967   The following description of indirect action persistence
2968   is an experimental behavior that may change without a prior notice.
2969
2970If ``RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP`` is not advertised,
2971indirect actions cannot be created until the device is started for the first time
2972and cannot be kept when the device is stopped.
2973However, PMD also does not flush them automatically on stop,
2974so the application must call ``rte_flow_action_handle_destroy()``
2975before stopping the device to ensure no indirect actions remain.
2976
2977If ``RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP`` is advertised,
2978this means that the PMD can keep at least some indirect actions
2979across device stop and start.
2980However, ``rte_eth_dev_configure()`` may fail if any indirect actions remain,
2981so the application must destroy them before attempting a reconfiguration.
2982Keeping may be only supported for certain kinds of indirect actions.
2983A kind is a combination of an action type and a value of its transfer bit.
2984For example: an indirect counter with the transfer bit reset.
2985To test if a particular kind of indirect actions is kept,
2986the application must try to create a valid indirect action of that kind
2987when the device is not started (either before the first start of after a stop).
2988If it fails with an error of type ``RTE_FLOW_ERROR_TYPE_STATE``,
2989application must destroy all indirect actions of this kind
2990before stopping the device.
2991If it succeeds, all indirect actions of the same kind are kept
2992when the device is stopped.
2993Indirect actions of a kept kind that are created when the device is stopped,
2994including the ones created for the test, will be kept after the device start.
2995
2996.. _table_rte_flow_action_handle:
2997
2998.. table:: INDIRECT
2999
3000   +---------------+
3001   | Field         |
3002   +===============+
3003   | no properties |
3004   +---------------+
3005
3006Action: ``INDIRECT_LIST``
3007^^^^^^^^^^^^^^^^^^^^^^^^^
3008
3009Indirect API creates a shared flow action with unique action handle.
3010Flow rules can access the shared flow action and resources related to
3011that action through the indirect action handle.
3012In addition, the API allows to update existing shared flow action configuration.
3013After the update completes, new action configuration
3014is available to all flows that reference that shared action.
3015
3016Indirect actions list expands the indirect action API:
3017
3018- Indirect action list creates a handle for one or several
3019  flow actions, while legacy indirect action handle references
3020  single action only.
3021  Input flow actions arranged in END terminated list.
3022
3023- Flow rule can provide rule specific configuration parameters to
3024  existing shared handle.
3025  Updates of flow rule specific configuration will not change the base
3026  action configuration.
3027  Base action configuration was set during the action creation.
3028
3029Indirect action list handle defines 2 types of resources:
3030
3031- Mutable handle resource can be changed during handle lifespan.
3032
3033- Immutable handle resource value is set during handle creation
3034  and cannot be changed.
3035
3036There are 2 types of mutable indirect handle contexts:
3037
3038- Action mutable context is always shared between all flows
3039  that referenced indirect actions list handle.
3040  Action mutable context can be changed by explicit invocation
3041  of indirect handle update function.
3042
3043- Flow mutable context is private to a flow.
3044  Flow mutable context can be updated by indirect list handle
3045  flow rule configuration.
3046
3047Indirect action types - immutable, action / flow mutable, are mutually
3048exclusive and depend on the action definition.
3049
3050If indirect list handle was created from a list of actions A1 / A2 ... An / END
3051indirect list flow action can update Ai flow mutable context in the
3052action configuration parameter.
3053Indirect list action configuration is and array [C1, C2,  .., Cn]
3054where Ci corresponds to Ai in the action handle source.
3055Ci configuration element points Ai flow mutable update, or it's NULL
3056if Ai has no flow mutable update.
3057Indirect list action configuration is NULL if the action has no flow mutable updates.
3058Otherwise it points to an array of n flow mutable configuration pointers.
3059
3060**Template API:**
3061
3062*Action template format:*
3063
3064``template .. indirect_list handle Htmpl conf Ctmpl ..``
3065
3066``mask     .. indirect_list handle Hmask conf Cmask ..``
3067
3068- If Htmpl was masked (Hmask != 0), it will be fixed in that template.
3069  Otherwise, indirect action value is set in a flow rule.
3070
3071- If Htmpl and Ctmpl[i] were masked (Hmask !=0 and Cmask[i] != 0),
3072  Htmpl's Ai action flow mutable context fill be updated to
3073  Ctmpl[i] values and will be fixed in that template.
3074
3075*Flow rule format:*
3076
3077``actions .. indirect_list handle Hflow conf Cflow ..``
3078
3079- If Htmpl was not masked in actions template, Hflow references an
3080  action of the same type as Htmpl.
3081
3082- Cflow[i] updates handle's Ai flow mutable configuration if
3083  the Ci was not masked in action template.
3084
3085.. _table_rte_flow_action_indirect_list:
3086
3087.. table:: INDIRECT_LIST
3088
3089   +------------------+----------------------------------+
3090   | Field            | Value                            |
3091   +==================+==================================+
3092   | ``handle``       | Indirect action list handle      |
3093   +------------------+----------------------------------+
3094   | ``conf``         | Flow mutable configuration array |
3095   +------------------+----------------------------------+
3096
3097.. code-block:: text
3098
3099   flow 1:
3100    / indirect handle H conf C1 /
3101                      |       |
3102                      |       |
3103                      |       |         flow 2:
3104                      |       |         / indirect handle H conf C2 /
3105                      |       |                           |      |
3106                      |       |                           |      |
3107                      |       |                           |      |
3108              =========================================================
3109              ^       |       |                           |      |
3110              |       |       V                           |      V
3111              |    ~~~~~~~~~~~~~~                      ~~~~~~~~~~~~~~~
3112              |     flow mutable                        flow mutable
3113              |     context 1                           context 2
3114              |    ~~~~~~~~~~~~~~                      ~~~~~~~~~~~~~~~
3115    indirect  |       |                                   |
3116    action    |       |                                   |
3117    context   |       V                                   V
3118              |   -----------------------------------------------------
3119              |                 action mutable context
3120              |   -----------------------------------------------------
3121              v                action immutable context
3122              =========================================================
3123
3124Action: ``MODIFY_FIELD``
3125^^^^^^^^^^^^^^^^^^^^^^^^
3126
3127Modify ``dst`` field according to ``op`` selected (set, addition,
3128subtraction) with ``width`` bits of data from ``src`` field.
3129
3130Any arbitrary header field (as well as mark, metadata or tag values)
3131can be used as both source and destination fields as set by ``field``.
3132The immediate value ``RTE_FLOW_FIELD_VALUE`` (or a pointer to it
3133``RTE_FLOW_FIELD_POINTER``) is allowed as a source only.
3134``RTE_FLOW_FIELD_START`` is used to point to the beginning of a packet.
3135See ``enum rte_flow_field_id`` for the list of supported fields.
3136
3137``op`` selects the operation to perform on a destination field:
3138
3139- ``set`` copies the data from ``src`` field to ``dst`` field.
3140- ``add`` adds together ``dst`` and ``src`` and stores the result into ``dst``.
3141- ``sub`` subtracts ``src`` from ``dst`` and stores the result into ``dst``.
3142
3143``width`` defines a number of bits to use from ``src`` field.
3144
3145``level`` is used to access any packet field on any encapsulation level:
3146
3147- ``0`` means the default behaviour. Depending on the packet type,
3148  it can mean outermost, innermost or anything in between.
3149- ``1`` requests access to the outermost packet encapsulation level.
3150- ``2`` and subsequent values requests access to the specified packet
3151  encapsulation level, from outermost to innermost (lower to higher values).
3152
3153``tag_index`` is the index of the header inside encapsulation level.
3154It is used to modify either ``VLAN`` or ``MPLS`` or ``TAG`` headers
3155which multiple of them might be supported in the same encapsulation level.
3156
3157.. note::
3158
3159   For ``RTE_FLOW_FIELD_TAG`` type, the tag array was provided in ``level``
3160   field and it is still supported for backwards compatibility.
3161   When ``tag_index`` is zero, the tag array is taken from ``level`` field.
3162
3163``type`` is used to specify (along with ``class_id``) the Geneve option
3164which is being modified.
3165This field is relevant only for ``RTE_FLOW_FIELD_GENEVE_OPT_XXXX`` type.
3166
3167``class_id`` is used to specify (along with ``type``) the Geneve option
3168which is being modified.
3169This field is relevant only for ``RTE_FLOW_FIELD_GENEVE_OPT_XXXX`` type.
3170
3171``flex_handle`` is used to specify the flex item pointer which is being
3172modified. ``flex_handle`` and ``level`` are mutually exclusive.
3173
3174``offset`` specifies the number of bits to skip from a field's start.
3175That allows performing a partial copy of the needed part or to divide a big
3176packet field into multiple smaller fields. Alternatively, ``offset`` allows
3177going past the specified packet field boundary to copy a field to an
3178arbitrary place in a packet, essentially providing a way to copy any part of
3179a packet to any other part of it.
3180
3181``value`` sets an immediate value to be used as a source or points to a
3182location of the value in memory. It is used instead of ``level`` and ``offset``
3183for ``RTE_FLOW_FIELD_VALUE`` and ``RTE_FLOW_FIELD_POINTER`` respectively.
3184The data in memory should be presented exactly in the same byte order and
3185length as in the relevant flow item, i.e. data for field with type
3186``RTE_FLOW_FIELD_MAC_DST`` should follow the conventions of ``dst`` field
3187in ``rte_flow_item_eth`` structure, with type ``RTE_FLOW_FIELD_IPV6_SRC`` -
3188``rte_flow_item_ipv6`` conventions, and so on. If the field size is larger than
318916 bytes the pattern can be provided as pointer only.
3190
3191The bitfield extracted from the memory being applied as second operation
3192parameter is defined by action width and by the destination field offset.
3193Application should provide the data in immediate value memory (either as
3194buffer or by pointer) exactly as item field without any applied explicit offset,
3195and destination packet field (with specified width and bit offset) will be
3196replaced by immediate source bits from the same bit offset. For example,
3197to replace the third byte of MAC address with value 0x85, application should
3198specify destination width as 8, destination offset as 16, and provide immediate
3199value as sequence of bytes {xxx, xxx, 0x85, xxx, xxx, xxx}.
3200
3201The ``RTE_FLOW_FIELD_GENEVE_OPT_DATA`` type supports modifying only one DW in
3202single action and align to 32 bits.
3203For example, for modifying 16 bits start from offset 24,
32042 different actions should be prepared.
3205The first one includes ``offset=24`` and ``width=8``,
3206and the second one includes ``offset=32`` and ``width=8``.
3207Application should provide the data in immediate value memory only
3208for the single DW even though the offset is related to start of first DW.
3209For example, to replace the third byte of second DW in Geneve option data
3210with value ``0x85``, the application should specify destination width as ``8``,
3211destination offset as ``48``, and provide immediate value ``0xXXXX85XX``.
3212
3213.. _table_rte_flow_action_modify_field:
3214
3215.. table:: MODIFY_FIELD
3216
3217   +---------------+-------------------------+
3218   | Field         | Value                   |
3219   +===============+=========================+
3220   | ``op``        | operation to perform    |
3221   +---------------+-------------------------+
3222   | ``dst``       | destination field       |
3223   +---------------+-------------------------+
3224   | ``src``       | source field            |
3225   +---------------+-------------------------+
3226   | ``width``     | number of bits to use   |
3227   +---------------+-------------------------+
3228
3229.. _table_rte_flow_field_data:
3230
3231.. table:: destination/source field definition
3232
3233   +-----------------+----------------------------------------------------------+
3234   | Field           | Value                                                    |
3235   +=================+==========================================================+
3236   | ``field``       | ID: packet field, mark, meta, tag, immediate, pointer    |
3237   +-----------------+----------------------------------------------------------+
3238   | ``level``       | encapsulation level of a packet field                    |
3239   +-----------------+----------------------------------------------------------+
3240   | ``tag_index``   | tag index inside encapsulation level                     |
3241   +-----------------+----------------------------------------------------------+
3242   | ``type``        | Geneve option type                                       |
3243   +-----------------+----------------------------------------------------------+
3244   | ``class_id``    | Geneve option class ID                                   |
3245   +-----------------+----------------------------------------------------------+
3246   | ``flex_handle`` | flex item handle of a packet field                       |
3247   +-----------------+----------------------------------------------------------+
3248   | ``offset``      | number of bits to skip at the beginning                  |
3249   +-----------------+----------------------------------------------------------+
3250   | ``value``       | immediate value buffer (source field only, not           |
3251   |                 | applicable to destination) for RTE_FLOW_FIELD_VALUE      |
3252   |                 | field type                                               |
3253   |                 | This field is only 16 bytes, maybe not big enough for    |
3254   |                 | all NICs' flex item                                      |
3255   +-----------------+----------------------------------------------------------+
3256   | ``pvalue``      | pointer to immediate value data (source field only, not  |
3257   |                 | applicable to destination) for RTE_FLOW_FIELD_POINTER    |
3258   |                 | field type                                               |
3259   +-----------------+----------------------------------------------------------+
3260
3261Action: ``CONNTRACK``
3262^^^^^^^^^^^^^^^^^^^^^
3263
3264Create a conntrack (connection tracking) context with the provided information.
3265
3266In stateful session like TCP, the conntrack action provides the ability to
3267examine every packet of this connection and associate the state to every
3268packet. It will help to realize the stateful offload of connections with little
3269software participation. For example, the packets with invalid state may be
3270handled by the software. The control packets could be handled in the hardware.
3271The software just need to query the state of a connection when needed, and then
3272decide how to handle the flow rules and conntrack context.
3273
3274A conntrack context should be created via ``rte_flow_action_handle_create()``
3275before using. Then the handle with ``INDIRECT`` type is used for a flow rule
3276creation. If a flow rule with an opposite direction needs to be created, the
3277``rte_flow_action_handle_update()`` should be used to modify the direction.
3278
3279Not all the fields of the ``struct rte_flow_action_conntrack`` will be used
3280for a conntrack context creating, depending on the HW, and they should be
3281in host byte order. PMD should convert them into network byte order when
3282needed by the HW.
3283
3284The ``struct rte_flow_modify_conntrack`` should be used for an updating.
3285
3286The current conntrack context information could be queried via the
3287``rte_flow_action_handle_query()`` interface.
3288
3289.. _table_rte_flow_action_conntrack:
3290
3291.. table:: CONNTRACK
3292
3293   +--------------------------+-------------------------------------------------------------+
3294   | Field                    | Value                                                       |
3295   +==========================+=============================================================+
3296   | ``peer_port``            | peer port number                                            |
3297   +--------------------------+-------------------------------------------------------------+
3298   | ``is_original_dir``      | direction of this connection for creating flow rule         |
3299   +--------------------------+-------------------------------------------------------------+
3300   | ``enable``               | enable the conntrack context                                |
3301   +--------------------------+-------------------------------------------------------------+
3302   | ``live_connection``      | one ack was seen for this connection                        |
3303   +--------------------------+-------------------------------------------------------------+
3304   | ``selective_ack``        | SACK enabled                                                |
3305   +--------------------------+-------------------------------------------------------------+
3306   | ``challenge_ack_passed`` | a challenge ack has passed                                  |
3307   +--------------------------+-------------------------------------------------------------+
3308   | ``last_direction``       | direction of the last passed packet                         |
3309   +--------------------------+-------------------------------------------------------------+
3310   | ``liberal_mode``         | only report state change                                    |
3311   +--------------------------+-------------------------------------------------------------+
3312   | ``state``                | current state                                               |
3313   +--------------------------+-------------------------------------------------------------+
3314   | ``max_ack_window``       | maximal window scaling factor                               |
3315   +--------------------------+-------------------------------------------------------------+
3316   | ``retransmission_limit`` | maximal retransmission times                                |
3317   +--------------------------+-------------------------------------------------------------+
3318   | ``original_dir``         | TCP parameters of the original direction                    |
3319   +--------------------------+-------------------------------------------------------------+
3320   | ``reply_dir``            | TCP parameters of the reply direction                       |
3321   +--------------------------+-------------------------------------------------------------+
3322   | ``last_window``          | window size of the last passed packet                       |
3323   +--------------------------+-------------------------------------------------------------+
3324   | ``last_seq``             | sequence number of the last passed packet                   |
3325   +--------------------------+-------------------------------------------------------------+
3326   | ``last_ack``             | acknowledgment number the last passed packet                |
3327   +--------------------------+-------------------------------------------------------------+
3328   | ``last_end``             | sum of ack number and length of the last passed packet      |
3329   +--------------------------+-------------------------------------------------------------+
3330
3331.. _table_rte_flow_tcp_dir_param:
3332
3333.. table:: configuration parameters for each direction
3334
3335   +---------------------+---------------------------------------------------------+
3336   | Field               | Value                                                   |
3337   +=====================+=========================================================+
3338   | ``scale``           | TCP window scaling factor                               |
3339   +---------------------+---------------------------------------------------------+
3340   | ``close_initiated`` | FIN sent from this direction                            |
3341   +---------------------+---------------------------------------------------------+
3342   | ``last_ack_seen``   | an ACK packet received                                  |
3343   +---------------------+---------------------------------------------------------+
3344   | ``data_unacked``    | unacknowledged data for packets from this direction     |
3345   +---------------------+---------------------------------------------------------+
3346   | ``sent_end``        | max{seq + len} seen in sent packets                     |
3347   +---------------------+---------------------------------------------------------+
3348   | ``reply_end``       | max{sack + max{win, 1}} seen in reply packets           |
3349   +---------------------+---------------------------------------------------------+
3350   | ``max_win``         | max{max{win, 1}} + {sack - ack} seen in sent packets    |
3351   +---------------------+---------------------------------------------------------+
3352   | ``max_ack``         | max{ack} + seen in sent packets                         |
3353   +---------------------+---------------------------------------------------------+
3354
3355.. _table_rte_flow_modify_conntrack:
3356
3357.. table:: update a conntrack context
3358
3359   +----------------+-------------------------------------------------+
3360   | Field          | Value                                           |
3361   +================+=================================================+
3362   | ``new_ct``     | new conntrack information                       |
3363   +----------------+-------------------------------------------------+
3364   | ``direction``  | direction will be updated                       |
3365   +----------------+-------------------------------------------------+
3366   | ``state``      | other fields except direction will be updated   |
3367   +----------------+-------------------------------------------------+
3368   | ``reserved``   | reserved bits                                   |
3369   +----------------+-------------------------------------------------+
3370
3371Action: ``METER_COLOR``
3372^^^^^^^^^^^^^^^^^^^^^^^
3373
3374Color the packet to reflect the meter color result.
3375
3376The meter action must be configured before meter color action.
3377Meter color action is set to a color to reflect the meter color result.
3378Set the meter color in the mbuf to the selected color.
3379The meter color action output color is the output color of the packet,
3380which is set in the packet meta-data (i.e. struct ``rte_mbuf::sched::color``)
3381
3382.. _table_rte_flow_action_meter_color:
3383
3384.. table:: METER_COLOR
3385
3386   +-----------------+--------------+
3387   | Field           | Value        |
3388   +=================+==============+
3389   | ``meter_color`` | Packet color |
3390   +-----------------+--------------+
3391
3392Action: ``PORT_REPRESENTOR``
3393^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3394
3395At embedded switch level, send matching traffic to the given ethdev.
3396
3397Term **ethdev** and the concept of **port representor** are synonymous.
3398The **represented port** is an *entity* plugged to the embedded switch
3399at the opposite end of the "wire" leading to the ethdev.
3400
3401::
3402
3403    .--------------------.
3404    |  PORT_REPRESENTOR  |  Ethdev (Application Port Referred to by its ID)
3405    '--------------------'
3406              /\
3407              ||
3408      .----------------.
3409      |  Logical Port  |
3410      '----------------'
3411              /\
3412              ||
3413              ||
3414              ||
3415         .----------.       .--------------------.
3416         |  Switch  |  <==  |  Matching Traffic  |
3417         '----------'       '--------------------'
3418              :
3419               :
3420              :
3421               :
3422      .----------------.
3423      |  Logical Port  |
3424      '----------------'
3425              :
3426               :
3427    .--------------------.
3428    |  REPRESENTED_PORT  |  Net / Guest / Another Ethdev (Same Application)
3429    '--------------------'
3430
3431
3432- Requires `Attribute: Transfer`_.
3433
3434.. _table_rte_flow_action_ethdev:
3435
3436.. table:: ``struct rte_flow_action_ethdev``
3437
3438   +-------------+----------------+
3439   | Field       | Value          |
3440   +=============+================+
3441   | ``port_id`` | ethdev port ID |
3442   +-------------+----------------+
3443
3444See also `Item: PORT_REPRESENTOR`_.
3445
3446Action: ``REPRESENTED_PORT``
3447^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3448
3449At embedded switch level, send matching traffic to
3450the entity represented by the given ethdev.
3451
3452Term **ethdev** and the concept of **port representor** are synonymous.
3453The **represented port** is an *entity* plugged to the embedded switch
3454at the opposite end of the "wire" leading to the ethdev.
3455
3456::
3457
3458    .--------------------.
3459    |  PORT_REPRESENTOR  |  Ethdev (Application Port Referred to by its ID)
3460    '--------------------'
3461              :
3462               :
3463      .----------------.
3464      |  Logical Port  |
3465      '----------------'
3466              :
3467               :
3468              :
3469               :
3470         .----------.       .--------------------.
3471         |  Switch  |  <==  |  Matching Traffic  |
3472         '----------'       '--------------------'
3473              ||
3474              ||
3475              ||
3476              \/
3477      .----------------.
3478      |  Logical Port  |
3479      '----------------'
3480              ||
3481              \/
3482    .--------------------.
3483    |  REPRESENTED_PORT  |  Net / Guest / Another Ethdev (Same Application)
3484    '--------------------'
3485
3486
3487- Requires `Attribute: Transfer`_.
3488
3489This action is meant to use the same structure as `Action: PORT_REPRESENTOR`_.
3490
3491See also `Item: REPRESENTED_PORT`_.
3492
3493Action: ``METER_MARK``
3494^^^^^^^^^^^^^^^^^^^^^^
3495
3496Meters a packet stream and marks its packets with colors.
3497
3498Unlike the ``METER`` action, policing is optional and may be
3499performed later with the help of the ``METER_COLOR`` item.
3500The profile and/or policy objects have to be created
3501using the rte_mtr_profile_add()/rte_mtr_policy_add() API.
3502Pointers to these objects are used as action parameters
3503and need to be retrieved using the rte_mtr_profile_get() API
3504and rte_mtr_policy_get() API respectively.
3505
3506.. _table_rte_flow_action_meter_mark:
3507
3508.. table:: METER_MARK
3509
3510   +------------------+----------------------+
3511   | Field            | Value                |
3512   +==================+======================+
3513   | ``profile``      | Meter profile object |
3514   +------------------+----------------------+
3515   | ``policy``       | Meter policy object  |
3516   +------------------+----------------------+
3517
3518Action: ``QUOTA``
3519^^^^^^^^^^^^^^^^^
3520
3521Update ``quota`` value and set packet quota state.
3522
3523If the ``quota`` value after update is non-negative,
3524the packet quota state is set to ``RTE_FLOW_QUOTA_STATE_PASS``.
3525Otherwise, the packet quota state is set to ``RTE_FLOW_QUOTA_STATE_BLOCK``.
3526
3527The ``quota`` value is reduced according to ``mode`` setting.
3528
3529.. _table_rte_flow_action_quota:
3530
3531.. table:: QUOTA
3532
3533   +------------------+------------------------+
3534   | Field            | Value                  |
3535   +==================+========================+
3536   | ``mode``         | Quota operational mode |
3537   +------------------+------------------------+
3538   | ``quota``        | Quota value            |
3539   +------------------+------------------------+
3540
3541.. _rte_flow_quota_mode:
3542
3543.. table:: Quota update modes
3544
3545   +---------------------------------+-------------------------------------+
3546   | Value                           | Description                         |
3547   +=================================+=====================================+
3548   | ``RTE_FLOW_QUOTA_MODE_PACKET``  | Count packets                       |
3549   +---------------------------------+-------------------------------------+
3550   | ``RTE_FLOW_QUOTA_MODE_L2``      | Count packet bytes starting from L2 |
3551   +------------------+----------------------------------------------------+
3552   | ``RTE_FLOW_QUOTA_MODE_L3``      | Count packet bytes starting from L3 |
3553   +------------------+----------------------------------------------------+
3554
3555Action: ``SEND_TO_KERNEL``
3556^^^^^^^^^^^^^^^^^^^^^^^^^^
3557
3558Send packets to the kernel, without going to userspace at all.
3559
3560The packets will be received by the kernel driver sharing the same device
3561as the DPDK port on which this action is configured.
3562
3563Negative types
3564~~~~~~~~~~~~~~
3565
3566All specified pattern items (``enum rte_flow_item_type``) and actions
3567(``enum rte_flow_action_type``) use positive identifiers.
3568
3569The negative space is reserved for dynamic types generated by PMDs during
3570run-time. PMDs may encounter them as a result but must not accept negative
3571identifiers they are not aware of.
3572
3573A method to generate them remains to be defined.
3574
3575Application may use PMD dynamic items or actions in flow rules. In that case
3576size of configuration object in dynamic element must be a pointer size.
3577
3578Rules management
3579----------------
3580
3581A rather simple API with few functions is provided to fully manage flow
3582rules.
3583
3584Each created flow rule is associated with an opaque, PMD-specific handle
3585pointer. The application is responsible for keeping it until the rule is
3586destroyed.
3587
3588Flows rules are represented by ``struct rte_flow`` objects.
3589
3590Validation
3591~~~~~~~~~~
3592
3593Given that expressing a definite set of device capabilities is not
3594practical, a dedicated function is provided to check if a flow rule is
3595supported and can be created.
3596
3597.. code-block:: c
3598
3599   int
3600   rte_flow_validate(uint16_t port_id,
3601                     const struct rte_flow_attr *attr,
3602                     const struct rte_flow_item pattern[],
3603                     const struct rte_flow_action actions[],
3604                     struct rte_flow_error *error);
3605
3606The flow rule is validated for correctness and whether it could be accepted
3607by the device given sufficient resources. The rule is checked against the
3608current device mode and queue configuration. The flow rule may also
3609optionally be validated against existing flow rules and device resources.
3610This function has no effect on the target device.
3611
3612The returned value is guaranteed to remain valid only as long as no
3613successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
3614in the meantime and no device parameter affecting flow rules in any way are
3615modified, due to possible collisions or resource limitations (although in
3616such cases ``EINVAL`` should not be returned).
3617
3618Arguments:
3619
3620- ``port_id``: port identifier of Ethernet device.
3621- ``attr``: flow rule attributes.
3622- ``pattern``: pattern specification (list terminated by the END pattern
3623  item).
3624- ``actions``: associated actions (list terminated by the END action).
3625- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3626  this structure in case of error only.
3627
3628Return values:
3629
3630- 0 if flow rule is valid and can be created. A negative errno value
3631  otherwise (``rte_errno`` is also set), the following errors are defined.
3632- ``-ENOSYS``: underlying device does not support this functionality.
3633- ``-EINVAL``: unknown or invalid rule specification.
3634- ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
3635  bit-masks are unsupported).
3636- ``EEXIST``: collision with an existing rule. Only returned if device
3637  supports flow rule collision checking and there was a flow rule
3638  collision. Not receiving this return code is no guarantee that creating
3639  the rule will not fail due to a collision.
3640- ``ENOMEM``: not enough memory to execute the function, or if the device
3641  supports resource validation, resource limitation on the device.
3642- ``-EBUSY``: action cannot be performed due to busy device resources, may
3643  succeed if the affected queues or even the entire port are in a stopped
3644  state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
3645
3646Creation
3647~~~~~~~~
3648
3649Creating a flow rule is similar to validating one, except the rule is
3650actually created and a handle returned.
3651
3652.. code-block:: c
3653
3654   struct rte_flow *
3655   rte_flow_create(uint16_t port_id,
3656                   const struct rte_flow_attr *attr,
3657                   const struct rte_flow_item pattern[],
3658                   const struct rte_flow_action *actions[],
3659                   struct rte_flow_error *error);
3660
3661Arguments:
3662
3663- ``port_id``: port identifier of Ethernet device.
3664- ``attr``: flow rule attributes.
3665- ``pattern``: pattern specification (list terminated by the END pattern
3666  item).
3667- ``actions``: associated actions (list terminated by the END action).
3668- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3669  this structure in case of error only.
3670
3671Return values:
3672
3673A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
3674to the positive version of one of the error codes defined for
3675``rte_flow_validate()``.
3676
3677Destruction
3678~~~~~~~~~~~
3679
3680Flow rules destruction is not automatic, and a queue or a port should not be
3681released if any are still attached to them. Applications must take care of
3682performing this step before releasing resources.
3683
3684.. code-block:: c
3685
3686   int
3687   rte_flow_destroy(uint16_t port_id,
3688                    struct rte_flow *flow,
3689                    struct rte_flow_error *error);
3690
3691
3692Failure to destroy a flow rule handle may occur when other flow rules depend
3693on it, and destroying it would result in an inconsistent state.
3694
3695This function is only guaranteed to succeed if handles are destroyed in
3696reverse order of their creation.
3697
3698Arguments:
3699
3700- ``port_id``: port identifier of Ethernet device.
3701- ``flow``: flow rule handle to destroy.
3702- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3703  this structure in case of error only.
3704
3705Return values:
3706
3707- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3708
3709Update
3710~~~~~~
3711
3712Update an existing flow rule with a new set of actions.
3713
3714.. code-block:: c
3715
3716   struct rte_flow *
3717   rte_flow_actions_update(uint16_t port_id,
3718                           struct rte_flow *flow,
3719                           const struct rte_flow_action *actions[],
3720                           struct rte_flow_error *error);
3721
3722Arguments:
3723
3724- ``port_id``: port identifier of Ethernet device.
3725- ``flow``: flow rule handle to update.
3726- ``actions``: associated actions (list terminated by the END action).
3727- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3728  this structure in case of error only.
3729
3730Return values:
3731
3732- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3733
3734Flush
3735~~~~~
3736
3737Convenience function to destroy all flow rule handles associated with a
3738port. They are released as with successive calls to ``rte_flow_destroy()``.
3739
3740.. code-block:: c
3741
3742   int
3743   rte_flow_flush(uint16_t port_id,
3744                  struct rte_flow_error *error);
3745
3746In the unlikely event of failure, handles are still considered destroyed and
3747no longer valid but the port must be assumed to be in an inconsistent state.
3748
3749Arguments:
3750
3751- ``port_id``: port identifier of Ethernet device.
3752- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3753  this structure in case of error only.
3754
3755Return values:
3756
3757- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3758
3759Query
3760~~~~~
3761
3762Query an existing flow rule.
3763
3764This function allows retrieving flow-specific data such as counters. Data
3765is gathered by special actions which must be present in the flow rule
3766definition.
3767
3768.. code-block:: c
3769
3770   int
3771   rte_flow_query(uint16_t port_id,
3772                  struct rte_flow *flow,
3773                  const struct rte_flow_action *action,
3774                  void *data,
3775                  struct rte_flow_error *error);
3776
3777Arguments:
3778
3779- ``port_id``: port identifier of Ethernet device.
3780- ``flow``: flow rule handle to query.
3781- ``action``: action to query, this must match prototype from flow rule.
3782- ``data``: pointer to storage for the associated query data type.
3783- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3784  this structure in case of error only.
3785
3786Return values:
3787
3788- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3789
3790Flow engine configuration
3791-------------------------
3792
3793Configure flow API management.
3794
3795An application may provide some parameters at the initialization phase about
3796rules engine configuration and/or expected flow rules characteristics.
3797These parameters may be used by PMD to preallocate resources and configure NIC.
3798
3799Configuration
3800~~~~~~~~~~~~~
3801
3802This function performs the flow API engine configuration and allocates
3803requested resources beforehand to avoid costly allocations later.
3804Expected number of resources in an application allows PMD to prepare
3805and optimize NIC hardware configuration and memory layout in advance.
3806``rte_flow_configure()`` must be called before any flow rule is created,
3807but after an Ethernet device is configured.
3808It also creates flow queues for asynchronous flow rules operations via
3809queue-based API, see `Asynchronous operations`_ section.
3810
3811.. code-block:: c
3812
3813   int
3814   rte_flow_configure(uint16_t port_id,
3815                      const struct rte_flow_port_attr *port_attr,
3816                      uint16_t nb_queue,
3817                      const struct rte_flow_queue_attr *queue_attr[],
3818                      struct rte_flow_error *error);
3819
3820Information about the number of available resources can be retrieved via
3821``rte_flow_info_get()`` API.
3822
3823.. code-block:: c
3824
3825   int
3826   rte_flow_info_get(uint16_t port_id,
3827                     struct rte_flow_port_info *port_info,
3828                     struct rte_flow_queue_info *queue_info,
3829                     struct rte_flow_error *error);
3830
3831Group Miss Actions
3832~~~~~~~~~~~~~~~~~~
3833
3834In an application, many flow rules share common group attributes, meaning they can be grouped and
3835classified together. A user can explicitly specify a set of actions performed on a packet when it
3836did not match any flows rules in a group using the following API:
3837
3838.. code-block:: c
3839
3840      int
3841      rte_flow_group_set_miss_actions(uint16_t port_id,
3842                                      uint32_t group_id,
3843                                      const struct rte_flow_group_attr *attr,
3844                                      const struct rte_flow_action actions[],
3845                                      struct rte_flow_error *error);
3846
3847For example, to configure a RTE_FLOW_TYPE_JUMP action as a miss action for ingress group 1:
3848
3849.. code-block:: c
3850
3851      struct rte_flow_group_attr attr = {.ingress = 1};
3852      struct rte_flow_action act[] = {
3853      /* Setting miss actions to jump to group 3 */
3854          [0] = {.type = RTE_FLOW_ACTION_TYPE_JUMP,
3855                 .conf = &(struct rte_flow_action_jump){.group = 3}},
3856          [1] = {.type = RTE_FLOW_ACTION_TYPE_END},
3857      };
3858      struct rte_flow_error err;
3859      rte_flow_group_set_miss_actions(port, 1, &attr, act, &err);
3860
3861.. _flow_templates:
3862
3863Flow templates
3864~~~~~~~~~~~~~~
3865
3866Oftentimes in an application, many flow rules share a common structure
3867(the same pattern and/or action list) so they can be grouped and classified
3868together. This knowledge may be used as a source of optimization by a PMD/HW.
3869The flow rule creation is done by selecting a table, a pattern template
3870and an actions template (which are bound to the table), and setting unique
3871values for the items and actions. This API is not thread-safe.
3872
3873Pattern templates
3874^^^^^^^^^^^^^^^^^
3875
3876The pattern template defines a common pattern (the item mask) without values.
3877The mask value is used to select a field to match on, spec/last are ignored.
3878The pattern template may be used by multiple tables and must not be destroyed
3879until all these tables are destroyed first.
3880
3881.. code-block:: c
3882
3883   struct rte_flow_pattern_template *
3884   rte_flow_pattern_template_create(uint16_t port_id,
3885       const struct rte_flow_pattern_template_attr *template_attr,
3886       const struct rte_flow_item pattern[],
3887       struct rte_flow_error *error);
3888
3889For example, to create a pattern template to match on the destination MAC:
3890
3891.. code-block:: c
3892
3893   const struct rte_flow_pattern_template_attr attr = {.ingress = 1};
3894   struct rte_flow_item_eth eth_m = {
3895       .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3896   };
3897   struct rte_flow_item pattern[] = {
3898       [0] = {.type = RTE_FLOW_ITEM_TYPE_ETH,
3899              .mask = &eth_m},
3900       [1] = {.type = RTE_FLOW_ITEM_TYPE_END,},
3901   };
3902   struct rte_flow_error err;
3903
3904   struct rte_flow_pattern_template *pattern_template =
3905           rte_flow_pattern_template_create(port, &attr, &pattern, &err);
3906
3907The concrete value to match on will be provided at the rule creation.
3908
3909Actions templates
3910^^^^^^^^^^^^^^^^^
3911
3912The actions template holds a list of action types to be used in flow rules.
3913The mask parameter allows specifying a shared constant value for every rule.
3914The actions template may be used by multiple tables and must not be destroyed
3915until all these tables are destroyed first.
3916
3917.. code-block:: c
3918
3919   struct rte_flow_actions_template *
3920   rte_flow_actions_template_create(uint16_t port_id,
3921       const struct rte_flow_actions_template_attr *template_attr,
3922       const struct rte_flow_action actions[],
3923       const struct rte_flow_action masks[],
3924       struct rte_flow_error *error);
3925
3926For example, to create an actions template with the same Mark ID
3927but different Queue Index for every rule:
3928
3929.. code-block:: c
3930
3931   rte_flow_actions_template_attr attr = {.ingress = 1};
3932   struct rte_flow_action act[] = {
3933   /* Mark ID is 4 for every rule, Queue Index is unique */
3934       [0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
3935              .conf = &(struct rte_flow_action_mark){.id = 4}},
3936       [1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
3937       [2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
3938   };
3939   struct rte_flow_action msk[] = {
3940   /* Assign to MARK mask any non-zero value to make it constant */
3941       [0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
3942              .conf = &(struct rte_flow_action_mark){.id = 1}},
3943       [1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
3944       [2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
3945   };
3946   struct rte_flow_error err;
3947
3948   struct rte_flow_actions_template *actions_template =
3949           rte_flow_actions_template_create(port, &attr, &act, &msk, &err);
3950
3951The concrete value for Queue Index will be provided at the rule creation.
3952
3953Template table
3954^^^^^^^^^^^^^^
3955
3956A template table combines a number of pattern and actions templates along with
3957shared flow rule attributes (group ID, priority and traffic direction).
3958This way a PMD/HW can prepare all the resources needed for efficient flow rules
3959creation in the datapath. To avoid any hiccups due to memory reallocation,
3960the maximum number of flow rules is defined at table creation time.
3961Any flow rule creation beyond the maximum table size is rejected.
3962Application may create another table to accommodate more rules in this case.
3963
3964.. code-block:: c
3965
3966   struct rte_flow_template_table *
3967   rte_flow_template_table_create(uint16_t port_id,
3968       const struct rte_flow_template_table_attr *table_attr,
3969       struct rte_flow_pattern_template *pattern_templates[],
3970       uint8_t nb_pattern_templates,
3971       struct rte_flow_actions_template *actions_templates[],
3972       uint8_t nb_actions_templates,
3973       struct rte_flow_error *error);
3974
3975A table can be created only after the Flow Rules management is configured
3976and pattern and actions templates are created.
3977
3978.. code-block:: c
3979
3980   rte_flow_template_table_attr table_attr = {
3981       .flow_attr.ingress = 1,
3982       .nb_flows = 10000;
3983   };
3984   uint8_t nb_pattern_templ = 1;
3985   struct rte_flow_pattern_template *pattern_templates[nb_pattern_templ];
3986   pattern_templates[0] = pattern_template;
3987   uint8_t nb_actions_templ = 1;
3988   struct rte_flow_actions_template *actions_templates[nb_actions_templ];
3989   actions_templates[0] = actions_template;
3990   struct rte_flow_error error;
3991
3992   struct rte_flow_template_table *table =
3993           rte_flow_template_table_create(port, &table_attr,
3994                   &pattern_templates, nb_pattern_templ,
3995                   &actions_templates, nb_actions_templ,
3996                   &error);
3997
3998Table Attribute: Specialize
3999^^^^^^^^^^^^^^^^^^^^^^^^^^^
4000
4001Application can help optimizing underlayer resources and insertion rate
4002by specializing template table.
4003Specialization is done by providing hints
4004in the template table attribute ``specialize``.
4005
4006This attribute is not mandatory for driver to implement.
4007If a hint is not supported, it will be silently ignored,
4008and no special optimization is done.
4009
4010If a table is specialized, the application should make sure the rules
4011comply with the table attribute.
4012The application functionality must not rely on the hints,
4013they are not replacing the matching criteria of flow rules.
4014
4015Template table resize
4016^^^^^^^^^^^^^^^^^^^^^
4017
4018The resizable template table API enables applications to dynamically adjust
4019capacity of template tables without disrupting the existing flow rules operation.
4020The resizable template table API allows applications to optimize
4021the memory usage and performance of template tables
4022according to the traffic conditions and requirements.
4023
4024A typical use case for the resizable template table API:
4025
4026  #. Create a resizable table with the initial capacity.
4027  #. Change the table flow rules capacity.
4028  #. Update table flow objects.
4029  #. Complete the table resize.
4030
4031A resizable table can be either in normal or resizable state.
4032When application begins to resize the table, its state is changed to resizable.
4033The table stays in resizable state until the application finishes resize procedure.
4034The application can resize a table in the normal state only.
4035
4036The application needs to set the ``RTE_FLOW_TABLE_SPECIALIZE_RESIZABLE`` bit in
4037the table attributes when creating a template table that can be resized,
4038and the bit cannot be set or cleared later.
4039
4040The application triggers the table resize by calling
4041the ``rte_flow_template_table_resize()`` function.
4042The resize process updates the table configuration to fit the new flow rules capacity.
4043Table resize does not change existing flow objects configuration.
4044The application can create new flow rules and modify or delete
4045existing flow rules while the table is resizing,
4046but the table performance might be slower than usual.
4047
4048Flow rules that existed before table resize are fully functional after table resize.
4049However, the application must update flow objects to match the new table configuration.
4050The application calls ``rte_flow_async_update_resized()`` to update flow object
4051for the new table configuration.
4052It should be called for flow rules created before table resize.
4053If called for flow rules created after table resize, the call should return success.
4054The application is free to call this API for all table flow rules.
4055
4056The application calls ``rte_flow_template_table_resize_complete()``
4057to return a table to normal state after it completed flow objects update.
4058
4059Testpmd commands (wrapped for clarity)::
4060
4061    # 1. Create resizable template table for 1 flow.
4062    testpmd> flow pattern_template 0 create ingress pattern_template_id 3
4063                  template eth / ipv4 / udp src mask 0xffff / end
4064    testpmd> flow actions_template 0 create ingress actions_template_id 7
4065                  template count  / rss / end
4066    testpmd> flow template_table 0 create table_id 101 resizable ingress
4067                  group 1 priority 0 rules_number 1
4068                  pattern_template 3 actions_template 7
4069
4070    # 2. Queue a flow rule.
4071    testpmd> flow queue 0 create 0 template_table 101
4072                  pattern_template 0 actions_template 0 postpone no
4073                  pattern eth / ipv4 / udp src spec 1 / end actions count / rss / end
4074
4075    # 3. Resize the template table
4076    #    The new table capacity is 32 rules
4077    testpmd> flow template_table 0 resize table_resize_id 101
4078                  table_resize_rules_num 32
4079
4080    # 4. Queue more flow rules.
4081    testpmd> flow queue 0 create 0 template_table 101
4082                  pattern_template 0 actions_template 0 postpone no
4083                  pattern eth / ipv4 / udp src spec 2 / end actions count / rss / end
4084    testpmd> flow queue 0 create 0 template_table 101
4085                  pattern_template 0 actions_template 0 postpone no
4086                  pattern eth / ipv4 / udp src spec 3 / end actions count / rss / end
4087    testpmd> flow queue 0 create 0 template_table 101
4088                  pattern_template 0 actions_template 0 postpone no
4089                  pattern eth / ipv4 / udp src spec 4 / end actions count / rss / end
4090
4091    # 5. Queue flow rules updates.
4092    # Rule 0 was created before table resize - must be updated.
4093    testpmd> flow queue 0 update_resized 0 rule 0
4094    # Rule 1 was created after table resize - flow pull returns success.
4095    testpmd> flow queue 0 update_resized 0 rule 1
4096
4097    # 6. Complete the table resize.
4098    testpmd> flow template_table 0 resize_complete table 101
4099
4100Asynchronous operations
4101-----------------------
4102
4103Flow rules management can be done via special lockless flow management queues.
4104
4105- Queue operations are asynchronous and not thread-safe.
4106
4107- Operations can thus be invoked by the app's datapath,
4108  packet processing can continue while queue operations are processed by NIC.
4109
4110- Number of flow queues is configured at initialization stage.
4111
4112- Available operation types: rule creation, rule destruction,
4113  indirect rule creation, indirect rule destruction, indirect rule update.
4114
4115- Operations may be reordered within a queue.
4116
4117- Operations can be postponed and pushed to NIC in batches.
4118
4119- Results pulling must be done on time to avoid queue overflows.
4120
4121- User data is returned as part of the result to identify an operation.
4122
4123- Flow handle is valid once the creation operation is enqueued and must be
4124  destroyed even if the operation is not successful and the rule is not inserted.
4125
4126- Application must wait for the creation operation result before enqueueing
4127  the deletion operation to make sure the creation is processed by NIC.
4128
4129The asynchronous flow rule insertion logic can be broken into two phases.
4130
4131#. Initialization stage as shown here:
4132
4133   .. _figure_rte_flow_async_init:
4134
4135   .. figure:: ../img/rte_flow_async_init.*
4136
4137#. Main loop as presented on a datapath application example:
4138
4139   .. _figure_rte_flow_async_usage:
4140
4141   .. figure:: ../img/rte_flow_async_usage.*
4142
4143Enqueue creation operation
4144~~~~~~~~~~~~~~~~~~~~~~~~~~
4145
4146Enqueueing a flow rule creation operation is similar to simple creation.
4147
4148.. code-block:: c
4149
4150   struct rte_flow *
4151   rte_flow_async_create(uint16_t port_id,
4152                         uint32_t queue_id,
4153                         const struct rte_flow_op_attr *op_attr,
4154                         struct rte_flow_template_table *template_table,
4155                         const struct rte_flow_item pattern[],
4156                         uint8_t pattern_template_index,
4157                         const struct rte_flow_action actions[],
4158                         uint8_t actions_template_index,
4159                         void *user_data,
4160                         struct rte_flow_error *error);
4161
4162A valid handle in case of success is returned. It must be destroyed later
4163by calling ``rte_flow_async_destroy()`` even if the rule is rejected by HW.
4164
4165Enqueue creation by index operation
4166~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4167
4168Enqueueing a flow rule creation operation to insert a rule at a table index.
4169
4170.. code-block:: c
4171
4172   struct rte_flow *
4173   rte_flow_async_create_by_index(uint16_t port_id,
4174                                  uint32_t queue_id,
4175                                  const struct rte_flow_op_attr *op_attr,
4176                                  struct rte_flow_template_table *template_table,
4177                                  uint32_t rule_index,
4178                                  const struct rte_flow_action actions[],
4179                                  uint8_t actions_template_index,
4180                                  void *user_data,
4181                                  struct rte_flow_error *error);
4182
4183A valid handle in case of success is returned. It must be destroyed later
4184by calling ``rte_flow_async_destroy()`` even if the rule is rejected by HW.
4185
4186Enqueue creation by index with pattern
4187~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4188
4189Enqueueing a flow rule creation operation to insert a rule at a table index with pattern.
4190
4191.. code-block:: c
4192
4193   struct rte_flow *
4194   rte_flow_async_create_by_index_with_pattern(uint16_t port_id,
4195                                               uint32_t queue_id,
4196                                               const struct rte_flow_op_attr *op_attr,
4197                                               struct rte_flow_template_table *template_table,
4198                                               uint32_t rule_index,
4199                                               const struct rte_flow_item pattern[],
4200                                               uint8_t pattern_template_index,
4201                                               const struct rte_flow_action actions[],
4202                                               uint8_t actions_template_index,
4203                                               void *user_data,
4204                                               struct rte_flow_error *error);
4205
4206Enqueue destruction operation
4207~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4208
4209Enqueueing a flow rule destruction operation is similar to simple destruction.
4210
4211.. code-block:: c
4212
4213   int
4214   rte_flow_async_destroy(uint16_t port_id,
4215                          uint32_t queue_id,
4216                          const struct rte_flow_op_attr *op_attr,
4217                          struct rte_flow *flow,
4218                          void *user_data,
4219                          struct rte_flow_error *error);
4220
4221Enqueue update operation
4222~~~~~~~~~~~~~~~~~~~~~~~~
4223
4224Enqueueing a flow rule update operation to replace actions in the existing rule.
4225
4226.. code-block:: c
4227
4228   int
4229   rte_flow_async_actions_update(uint16_t port_id,
4230                                 uint32_t queue_id,
4231                                 const struct rte_flow_op_attr *op_attr,
4232                                 struct rte_flow *flow,
4233                                 const struct rte_flow_action actions[],
4234                                 uint8_t actions_template_index,
4235                                 void *user_data,
4236                                 struct rte_flow_error *error);
4237
4238Enqueue indirect action creation operation
4239~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4240
4241Asynchronous version of indirect action creation API.
4242
4243.. code-block:: c
4244
4245   struct rte_flow_action_handle *
4246   rte_flow_async_action_handle_create(uint16_t port_id,
4247           uint32_t queue_id,
4248           const struct rte_flow_op_attr *q_ops_attr,
4249           const struct rte_flow_indir_action_conf *indir_action_conf,
4250           const struct rte_flow_action *action,
4251           void *user_data,
4252           struct rte_flow_error *error);
4253
4254A valid handle in case of success is returned. It must be destroyed later by
4255``rte_flow_async_action_handle_destroy()`` even if the rule was rejected.
4256
4257Enqueue indirect action destruction operation
4258~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4259
4260Asynchronous version of indirect action destruction API.
4261
4262.. code-block:: c
4263
4264   int
4265   rte_flow_async_action_handle_destroy(uint16_t port_id,
4266           uint32_t queue_id,
4267           const struct rte_flow_op_attr *q_ops_attr,
4268           struct rte_flow_action_handle *action_handle,
4269           void *user_data,
4270           struct rte_flow_error *error);
4271
4272Enqueue indirect action update operation
4273~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4274
4275Asynchronous version of indirect action update API.
4276
4277.. code-block:: c
4278
4279   int
4280   rte_flow_async_action_handle_update(uint16_t port_id,
4281           uint32_t queue_id,
4282           const struct rte_flow_op_attr *q_ops_attr,
4283           struct rte_flow_action_handle *action_handle,
4284           const void *update,
4285           void *user_data,
4286           struct rte_flow_error *error);
4287
4288Enqueue indirect action query operation
4289~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4290
4291Asynchronous version of indirect action query API.
4292
4293.. code-block:: c
4294
4295   int
4296   rte_flow_async_action_handle_query(uint16_t port_id,
4297           uint32_t queue_id,
4298           const struct rte_flow_op_attr *q_ops_attr,
4299           struct rte_flow_action_handle *action_handle,
4300           void *data,
4301           void *user_data,
4302           struct rte_flow_error *error);
4303
4304Push enqueued operations
4305~~~~~~~~~~~~~~~~~~~~~~~~
4306
4307Pushing all internally stored rules from a queue to the NIC.
4308
4309.. code-block:: c
4310
4311   int
4312   rte_flow_push(uint16_t port_id,
4313                 uint32_t queue_id,
4314                 struct rte_flow_error *error);
4315
4316There is the postpone attribute in the queue operation attributes.
4317When it is set, multiple operations can be bulked together and not sent to HW
4318right away to save SW/HW interactions and prioritize throughput over latency.
4319The application must invoke this function to actually push all outstanding
4320operations to HW in this case.
4321
4322Pull enqueued operations
4323~~~~~~~~~~~~~~~~~~~~~~~~
4324
4325Pulling asynchronous operations results.
4326
4327The application must invoke this function in order to complete asynchronous
4328flow rule operations and to receive flow rule operations statuses.
4329
4330.. code-block:: c
4331
4332   int
4333   rte_flow_pull(uint16_t port_id,
4334                 uint32_t queue_id,
4335                 struct rte_flow_op_result res[],
4336                 uint16_t n_res,
4337                 struct rte_flow_error *error);
4338
4339Multiple outstanding operation results can be pulled simultaneously.
4340User data may be provided during a flow creation/destruction in order
4341to distinguish between multiple operations. User data is returned as part
4342of the result to provide a method to detect which operation is completed.
4343
4344Calculate hash
4345~~~~~~~~~~~~~~
4346
4347Calculating hash of a packet in SW as it would be calculated in HW.
4348
4349The application can use this function to calculate the hash of a given packet
4350as it would be calculated in the HW.
4351
4352.. code-block:: c
4353
4354   int
4355   rte_flow_calc_table_hash(uint16_t port_id,
4356                            const struct rte_flow_template_table *table,
4357			                   const struct rte_flow_item pattern[],
4358                            uint8_t pattern_template_index,
4359			                   uint32_t *hash, struct rte_flow_error *error);
4360
4361Calculate encapsulation hash
4362~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4363
4364Calculating hash of a packet as it would be calculated by the HW, when encapsulating
4365a packet.
4366
4367When the HW execute an encapsulation action, for example VXLAN tunnel,
4368it may calculate an hash of the packet to be encapsulated.
4369This hash is stored in the outer header of the tunnel.
4370This allow better spreading of traffic.
4371
4372This function can be used for packets of a flow that are not offloaded and
4373pass through the SW instead of the HW, for example, SYN/FIN packets.
4374
4375.. _flow_isolated_mode:
4376
4377Flow isolated mode
4378------------------
4379
4380The general expectation for ingress traffic is that flow rules process it
4381first; the remaining unmatched or pass-through traffic usually ends up in a
4382queue (with or without RSS, locally or in some sub-device instance)
4383depending on the global configuration settings of a port.
4384
4385While fine from a compatibility standpoint, this approach makes drivers more
4386complex as they have to check for possible side effects outside of this API
4387when creating or destroying flow rules. It results in a more limited set of
4388available rule types due to the way device resources are assigned (e.g. no
4389support for the RSS action even on capable hardware).
4390
4391Given that nonspecific traffic can be handled by flow rules as well,
4392isolated mode is a means for applications to tell a driver that ingress on
4393the underlying port must be injected from the defined flow rules only; that
4394no default traffic is expected outside those rules.
4395
4396This has the following benefits:
4397
4398- Applications get finer-grained control over the kind of traffic they want
4399  to receive (no traffic by default).
4400
4401- More importantly they control at what point nonspecific traffic is handled
4402  relative to other flow rules, by adjusting priority levels.
4403
4404- Drivers can assign more hardware resources to flow rules and expand the
4405  set of supported rule types.
4406
4407Because toggling isolated mode may cause profound changes to the ingress
4408processing path of a driver, it may not be possible to leave it once
4409entered. Likewise, existing flow rules or global configuration settings may
4410prevent a driver from entering isolated mode.
4411
4412Applications relying on this mode are therefore encouraged to toggle it as
4413soon as possible after device initialization, ideally before the first call
4414to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
4415settings.
4416
4417Once effective, the following functionality has no effect on the underlying
4418port and may return errors such as ``ENOTSUP`` ("not supported"):
4419
4420- Toggling promiscuous mode.
4421- Toggling allmulticast mode.
4422- Configuring MAC addresses.
4423- Configuring multicast addresses.
4424- Configuring VLAN filters.
4425- Configuring global RSS settings.
4426
4427.. code-block:: c
4428
4429   int
4430   rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
4431
4432Arguments:
4433
4434- ``port_id``: port identifier of Ethernet device.
4435- ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
4436- ``error``: perform verbose error reporting if not NULL. PMDs initialize
4437  this structure in case of error only.
4438
4439Return values:
4440
4441- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
4442
4443Verbose error reporting
4444-----------------------
4445
4446The defined *errno* values may not be accurate enough for users or
4447application developers who want to investigate issues related to flow rules
4448management. A dedicated error object is defined for this purpose:
4449
4450.. code-block:: c
4451
4452   enum rte_flow_error_type {
4453       RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
4454       RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
4455       RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
4456       RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
4457       RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
4458       RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
4459       RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
4460       RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
4461       RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
4462       RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
4463       RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
4464       RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
4465   };
4466
4467   struct rte_flow_error {
4468       enum rte_flow_error_type type; /**< Cause field and error types. */
4469       const void *cause; /**< Object responsible for the error. */
4470       const char *message; /**< Human-readable error message. */
4471   };
4472
4473Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
4474remaining fields can be ignored. Other error types describe the type of the
4475object pointed by ``cause``.
4476
4477If non-NULL, ``cause`` points to the object responsible for the error. For a
4478flow rule, this may be a pattern item or an individual action.
4479
4480If non-NULL, ``message`` provides a human-readable error message.
4481
4482This object is normally allocated by applications and set by PMDs in case of
4483error, the message points to a constant string which does not need to be
4484freed by the application, however its pointer can be considered valid only
4485as long as its associated DPDK port remains configured. Closing the
4486underlying device or unloading the PMD invalidates it.
4487
4488Helpers
4489-------
4490
4491Error initializer
4492~~~~~~~~~~~~~~~~~
4493
4494.. code-block:: c
4495
4496   static inline int
4497   rte_flow_error_set(struct rte_flow_error *error,
4498                      int code,
4499                      enum rte_flow_error_type type,
4500                      const void *cause,
4501                      const char *message);
4502
4503This function initializes ``error`` (if non-NULL) with the provided
4504parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
4505then returned.
4506
4507Object conversion
4508~~~~~~~~~~~~~~~~~
4509
4510.. code-block:: c
4511
4512   int
4513   rte_flow_conv(enum rte_flow_conv_op op,
4514                 void *dst,
4515                 size_t size,
4516                 const void *src,
4517                 struct rte_flow_error *error);
4518
4519Convert ``src`` to ``dst`` according to operation ``op``. Possible
4520operations include:
4521
4522- Attributes, pattern item or action duplication.
4523- Duplication of an entire pattern or list of actions.
4524- Duplication of a complete flow rule description.
4525- Pattern item or action name retrieval.
4526
4527Tunneled traffic offload
4528~~~~~~~~~~~~~~~~~~~~~~~~
4529
4530rte_flow API provides the building blocks for vendor-agnostic flow
4531classification offloads. The rte_flow "patterns" and "actions"
4532primitives are fine-grained, thus enabling DPDK applications the
4533flexibility to offload network stacks and complex pipelines.
4534Applications wishing to offload tunneled traffic are required to use
4535the rte_flow primitives, such as group, meta, mark, tag, and others to
4536model their high-level objects.  The hardware model design for
4537high-level software objects is not trivial.  Furthermore, an optimal
4538design is often vendor-specific.
4539
4540When hardware offloads tunneled traffic in multi-group logic,
4541partially offloaded packets may arrive to the application after they
4542were modified in hardware. In this case, the application may need to
4543restore the original packet headers. Consider the following sequence:
4544The application decaps a packet in one group and jumps to a second
4545group where it tries to match on a 5-tuple, that will miss and send
4546the packet to the application. In this case, the application does not
4547receive the original packet but a modified one. Also, in this case,
4548the application cannot match on the outer header fields, such as VXLAN
4549vni and 5-tuple.
4550
4551There are several possible ways to use rte_flow "patterns" and
4552"actions" to resolve the issues above. For example:
4553
45541 Mapping headers to a hardware registers using the
4555rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects.
4556
45572 Apply the decap only at the last offload stage after all the
4558"patterns" were matched and the packet will be fully offloaded.
4559
4560Every approach has its pros and cons and is highly dependent on the
4561hardware vendor.  For example, some hardware may have a limited number
4562of registers while other hardware could not support inner actions and
4563must decap before accessing inner headers.
4564
4565The tunnel offload model resolves these issues. The model goals are:
4566
45671 Provide a unified application API to offload tunneled traffic that
4568is capable to match on outer headers after decap.
4569
45702 Allow the application to restore the outer header of partially
4571offloaded packets.
4572
4573The tunnel offload model does not introduce new elements to the
4574existing RTE flow model and is implemented as a set of helper
4575functions.
4576
4577For the application to work with the tunnel offload API it
4578has to adjust flow rules in multi-table tunnel offload in the
4579following way:
4580
45811 Remove explicit call to decap action and replace it with PMD actions
4582obtained from rte_flow_tunnel_decap_and_set() helper.
4583
45842 Add PMD items obtained from rte_flow_tunnel_match() helper to all
4585other rules in the tunnel offload sequence.
4586
4587The model requirements:
4588
4589Software application must initialize
4590rte_tunnel object with tunnel parameters before calling
4591rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
4592
4593PMD actions array obtained in rte_flow_tunnel_decap_set() must be
4594released by application with rte_flow_action_release() call.
4595
4596PMD items array obtained with rte_flow_tunnel_match() must be released
4597by application with rte_flow_item_release() call.  Application can
4598release PMD items and actions after rule was created. However, if the
4599application needs to create additional rule for the same tunnel it
4600will need to obtain PMD items again.
4601
4602Application cannot destroy rte_tunnel object before it releases all
4603PMD actions & PMD items referencing that tunnel.
4604
4605Caveats
4606-------
4607
4608- DPDK does not keep track of flow rules definitions or flow rule objects
4609  automatically. Applications may keep track of the former and must keep
4610  track of the latter. PMDs may also do it for internal needs, however this
4611  must not be relied on by applications.
4612
4613- Flow rules are not maintained between successive port initializations. An
4614  application exiting without releasing them and restarting must re-create
4615  them from scratch.
4616
4617- API operations are synchronous and blocking (``EAGAIN`` cannot be
4618  returned).
4619
4620- Stopping the data path (TX/RX) should not be necessary when managing flow
4621  rules. If this cannot be achieved naturally or with workarounds (such as
4622  temporarily replacing the burst function pointers), an appropriate error
4623  code must be returned (``EBUSY``).
4624
4625- Applications, not PMDs, are responsible for maintaining flow rules
4626  configuration when closing, stopping or restarting a port or performing other
4627  actions which may affect them.
4628  Applications must assume that after port close, stop or restart all flows
4629  related to that port are not valid, hardware rules are destroyed and relevant
4630  PMD resources are released.
4631
4632For devices exposing multiple ports sharing global settings affected by flow
4633rules:
4634
4635- All ports under DPDK control must behave consistently, PMDs are
4636  responsible for making sure that existing flow rules on a port are not
4637  affected by other ports.
4638
4639- Ports not under DPDK control (unaffected or handled by other applications)
4640  are user's responsibility. They may affect existing flow rules and cause
4641  undefined behavior. PMDs aware of this may prevent flow rules creation
4642  altogether in such cases.
4643
4644PMD interface
4645-------------
4646
4647The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
4648API/ABI versioning constraints as it is not exposed to applications and may
4649evolve independently.
4650
4651The PMD interface is based on callbacks pointed by the ``struct rte_flow_ops``.
4652
4653- PMD callbacks implement exactly the interface described in `Rules
4654  management`_, except for the port ID argument which has already been
4655  converted to a pointer to the underlying ``struct rte_eth_dev``.
4656
4657- Public API functions do not process flow rules definitions at all before
4658  calling PMD functions (no basic error checking, no validation
4659  whatsoever). They only make sure these callbacks are non-NULL or return
4660  the ``ENOSYS`` (function not supported) error.
4661
4662This interface additionally defines the following helper function:
4663
4664- ``rte_flow_ops_get()``: get generic flow operations structure from a
4665  port.
4666
4667If PMD interfaces don't support re-entrancy/multi-thread safety,
4668the rte_flow API functions will protect threads by mutex per port.
4669The application can check whether ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE``
4670is set in ``dev_flags``, meaning the PMD is thread-safe regarding rte_flow,
4671so the API level protection is disabled.
4672Please note that this API-level mutex protects only rte_flow functions,
4673other control path functions are not in scope.
4674
4675Device compatibility
4676--------------------
4677
4678No known implementation supports all the described features.
4679
4680Unsupported features or combinations are not expected to be fully emulated
4681in software by PMDs for performance reasons. Partially supported features
4682may be completed in software as long as hardware performs most of the work
4683(such as queue redirection and packet recognition).
4684
4685However PMDs are expected to do their best to satisfy application requests
4686by working around hardware limitations as long as doing so does not affect
4687the behavior of existing flow rules.
4688
4689The following sections provide a few examples of such cases and describe how
4690PMDs should handle them, they are based on limitations built into the
4691previous APIs.
4692
4693Global bit-masks
4694~~~~~~~~~~~~~~~~
4695
4696Each flow rule comes with its own, per-layer bit-masks, while hardware may
4697support only a single, device-wide bit-mask for a given layer type, so that
4698two IPv4 rules cannot use different bit-masks.
4699
4700The expected behavior in this case is that PMDs automatically configure
4701global bit-masks according to the needs of the first flow rule created.
4702
4703Subsequent rules are allowed only if their bit-masks match those, the
4704``EEXIST`` error code should be returned otherwise.
4705
4706Unsupported layer types
4707~~~~~~~~~~~~~~~~~~~~~~~
4708
4709Many protocols can be simulated by crafting patterns with the `Item: RAW`_
4710type.
4711
4712PMDs can rely on this capability to simulate support for protocols with
4713headers not directly recognized by hardware.
4714
4715``ANY`` pattern item
4716~~~~~~~~~~~~~~~~~~~~
4717
4718This pattern item stands for anything, which can be difficult to translate
4719to something hardware would understand, particularly if followed by more
4720specific types.
4721
4722Consider the following pattern:
4723
4724.. _table_rte_flow_unsupported_any:
4725
4726.. table:: Pattern with ANY as L3
4727
4728   +-------+-----------------------+
4729   | Index | Item                  |
4730   +=======+=======================+
4731   | 0     | ETHER                 |
4732   +-------+-----+---------+-------+
4733   | 1     | ANY | ``num`` | ``1`` |
4734   +-------+-----+---------+-------+
4735   | 2     | TCP                   |
4736   +-------+-----------------------+
4737   | 3     | END                   |
4738   +-------+-----------------------+
4739
4740Knowing that TCP does not make sense with something other than IPv4 and IPv6
4741as L3, such a pattern may be translated to two flow rules instead:
4742
4743.. _table_rte_flow_unsupported_any_ipv4:
4744
4745.. table:: ANY replaced with IPV4
4746
4747   +-------+--------------------+
4748   | Index | Item               |
4749   +=======+====================+
4750   | 0     | ETHER              |
4751   +-------+--------------------+
4752   | 1     | IPV4 (zeroed mask) |
4753   +-------+--------------------+
4754   | 2     | TCP                |
4755   +-------+--------------------+
4756   | 3     | END                |
4757   +-------+--------------------+
4758
4759|
4760
4761.. _table_rte_flow_unsupported_any_ipv6:
4762
4763.. table:: ANY replaced with IPV6
4764
4765   +-------+--------------------+
4766   | Index | Item               |
4767   +=======+====================+
4768   | 0     | ETHER              |
4769   +-------+--------------------+
4770   | 1     | IPV6 (zeroed mask) |
4771   +-------+--------------------+
4772   | 2     | TCP                |
4773   +-------+--------------------+
4774   | 3     | END                |
4775   +-------+--------------------+
4776
4777Note that as soon as a ANY rule covers several layers, this approach may
4778yield a large number of hidden flow rules. It is thus suggested to only
4779support the most common scenarios (anything as L2 and/or L3).
4780
4781Unsupported actions
4782~~~~~~~~~~~~~~~~~~~
4783
4784- When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
4785  and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
4786  software as long as the target queue is used by a single rule.
4787
4788- When a single target queue is provided, `Action: RSS`_ can also be
4789  implemented through `Action: QUEUE`_.
4790
4791Flow rules priority
4792~~~~~~~~~~~~~~~~~~~
4793
4794While it would naturally make sense, flow rules cannot be assumed to be
4795processed by hardware in the same order as their creation for several
4796reasons:
4797
4798- They may be managed internally as a tree or a hash table instead of a
4799  list.
4800- Removing a flow rule before adding another one can either put the new rule
4801  at the end of the list or reuse a freed entry.
4802- Duplication may occur when packets are matched by several rules.
4803
4804For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
4805predictable behavior is only guaranteed by using different priority levels.
4806
4807Priority levels are not necessarily implemented in hardware, or may be
4808severely limited (e.g. a single priority bit).
4809
4810For these reasons, priority levels may be implemented purely in software by
4811PMDs.
4812
4813- For devices expecting flow rules to be added in the correct order, PMDs
4814  may destroy and re-create existing rules after adding a new one with
4815  a higher priority.
4816
4817- A configurable number of dummy or empty rules can be created at
4818  initialization time to save high priority slots for later.
4819
4820- In order to save priority levels, PMDs may evaluate whether rules are
4821  likely to collide and adjust their priority accordingly.
4822
4823
4824.. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/
4825