Skip to content

Commit 0bd37d3

Browse files
anatolyburakovbruce-richardson
authored andcommitted
doc/ice: document protocol agnostic filtering
Current documentation for protocol agnostic filtering for ICE driver is a bit terse and relies on a lot of assumed knowledge. Document the feature better and make all of the assumptions explicit. Signed-off-by: Anatoly Burakov <[email protected]> Acked-by: Vladimir Medvedkin <[email protected]>
1 parent c63646d commit 0bd37d3

File tree

1 file changed

+219
-11
lines changed

1 file changed

+219
-11
lines changed

doc/guides/nics/ice.rst

Lines changed: 219 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,228 @@ For each engine, a list of supported patterns is maintained in a global array
624624
named ``ice_<engine>_supported_pattern``. The Ice PMD will reject any rule with
625625
a pattern that is not included in the supported list.
626626

627-
One notable feature is the ice PMD's ability to leverage the Raw pattern,
628-
enabling protocol-agnostic flow offloading. Here is an example of creating
629-
a rule that matches an IPv4 destination address of 1.2.3.4 and redirects it to
630-
queue 3 using a raw pattern::
631-
632-
flow create 0 ingress group 2 pattern raw \
633-
pattern spec \
634-
00000000000000000000000008004500001400004000401000000000000001020304 \
635-
pattern mask \
636-
000000000000000000000000000000000000000000000000000000000000ffffffff \
637-
end actions queue index 3 / mark id 3 / end
627+
Protocol Agnostic Filtering
628+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
629+
630+
One notable feature is the ice PMD's ability to leverage the Raw pattern, enabling protocol-agnostic flow offloading.
631+
This feature allows users to create flow rules for any protocol recognized by the hardware parser, by manually specifying the raw packet structure.
632+
Therefore, flow offloading can be used even in cases where desired protocol isn't explicitly supported by RTE_FLOW interface.
633+
634+
Raw Pattern Components
635+
++++++++++++++++++++++
636+
637+
Raw patterns consist of two key components:
638+
639+
**Pattern Spec**
640+
An ASCII hexadecimal string representing the complete packet structure that defines the packet type and protocol layout.
641+
The hardware parser analyzes this structure to determine the packet type (PTYPE) and identify protocol headers and their offsets.
642+
This specification must represent a valid packet structure that the hardware can parse and classify.
643+
If the hardware parser does not support a particular protocol stack, it may not correctly identify the packet type.
644+
645+
**Pattern Mask**
646+
An ASCII hexadecimal string of the same length as the spec that determines which specific fields within the packet will be extracted and used for matching.
647+
The mask control field extraction without affecting the packet type identification.
648+
649+
.. note::
650+
Raw pattern must be the only flow item in the flow item list.
651+
652+
Generating Raw Pattern Values
653+
+++++++++++++++++++++++++++++
654+
655+
To create raw patterns, follow these steps:
656+
657+
1. **Verify parser support**: Confirm that the hardware parser supports the protocol combination needed for the intended flow rule.
658+
This can be checked against the documentation for the DDP package currently in use.
659+
660+
2. **Build the packet template**: Create a complete, valid packet header with all necessary sections (Ethernet, IP, UDP/TCP, etc.) using the exact field values that need to be matched.
661+
662+
3. **Convert to hexadecimal**: Transform the entire header into a continuous ASCII hexadecimal string, with each byte represented as two hex characters.
663+
664+
4. **Create the extraction mask**: Generate a mask of the same length as the spec, where set bits would indicate the fields used for extraction/matching.
665+
666+
VPP project's `flow_parse.py` script can be used to generate packet templates and masks for raw patterns.
667+
This tool takes a human-readable flow description and outputs the corresponding ASCII hexadecimal spec and mask.
668+
This script can be found under ``extras/packetforge`` in `VPP project <https://github.com/FDio/vpp/blob/master/extras/packetforge/flow_parse.py>`_.
669+
670+
Example usage:
671+
672+
.. code-block:: console
673+
674+
python3 flow_parse.py --show -p "mac()/ipv4(src=1.1.1.1,dst=2.2.2.2)/udp()"
675+
676+
Output:
677+
678+
.. code-block:: console
679+
680+
{'flow': {'generic': {'pattern': {'spec': b'00000000000100000000000208004500001c000000000011000001010101020202020000000000080000',
681+
'mask': b'0000000000000000000000000000000000000000000000000000ffffffffffffffff0000000000000000'}}}}
682+
683+
.. note::
684+
Ensure the spec represents complete protocol headers, as the hardware parser processes fields at 16-bit boundaries.
685+
Incomplete or truncated headers may result in unpredictable field extraction behavior.
686+
687+
Action Support and Usage
688+
^^^^^^^^^^^^^^^^^^^^^^^^
689+
690+
After constructing the raw pattern spec and mask, they can be used in the flow API with pattern type "raw".
691+
692+
The following is an example of a minimal Ethernet + IPv4 header template.
693+
Source and destination IPv4 addresses are part of the match key; all other fields are ignored.
694+
695+
Spec (packet template):
696+
697+
.. code-block::
698+
699+
000000000001 Destination MAC (6 bytes)
700+
000000000002 Source MAC (6 bytes)
701+
0800 EtherType = IPv4
702+
4500001c0000000000110000 IPv4 header, protocol = UDP
703+
01010101 Source IP = 1.1.1.1
704+
02020202 Destination IP = 2.2.2.2
705+
0000000000080000 UDP header
706+
707+
Mask:
708+
709+
.. code-block::
710+
711+
000000000000 Destination MAC (ignored)
712+
000000000000 Source MAC (ignored)
713+
0000 EtherType (ignored)
714+
000000000000000000000000 IPv4/UDP header (ignored)
715+
ffffffff Source IP (match all 32 bits)
716+
ffffffff Destination IP (match all 32 bits)
717+
0000000000000000 UDP header (ignored)
718+
719+
This spec will match any non-fragmented IPv4/UDP packet whose source IP is 1.1.1.1 and destination IP is 2.2.2.2.
720+
721+
Currently, the following actions are supported:
722+
723+
- **mark**: Attaches a user-defined integer value to matching packets. Can be specified together with another action.
724+
725+
- **queue**: Directs matching packets to a specific receive queue.
726+
727+
- **drop**: Discards matching packets at the hardware level.
728+
729+
- **rss**: Enables Receive Side Scaling (RSS) for matching packets.
730+
731+
Constraints:
732+
* For RSS, only the global configuration is used; per-rule queue lists or RSS keys are not supported.
733+
734+
To direct matching packets to a specific queue, and set mbuf FDIR metadata in:
735+
736+
.. code-block:: console
737+
738+
flow create 0 ingress pattern raw \
739+
pattern spec 00000000000100000000000208004500001c000000000011000001010101020202020000000000080000 \
740+
pattern mask 0000000000000000000000000000000000000000000000000000ffffffffffffffff0000000000000000 / end \
741+
actions queue index 3 mark id 3 / end
742+
743+
Equivalent C code using the ``rte_flow`` API:
744+
745+
.. code-block:: c
746+
747+
/* Hex string for the packet spec (Ethernet + IPv4 + UDP header) */
748+
static const uint8_t raw_pattern_spec[] = {
749+
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* Destination MAC */
750+
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, /* Source MAC */
751+
0x08, 0x00, /* EtherType: IPv4 */
752+
0x45, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00,
753+
0x00, 0x11, 0x00, 0x00, /* IPv4 header, protocol UDP */
754+
0x01, 0x01, 0x01, 0x01, /* Source IP: 1.1.1.1 */
755+
0x02, 0x02, 0x02, 0x02, /* Destination IP: 2.2.2.2 */
756+
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00 /* UDP header */
757+
};
758+
759+
/* Mask indicating which fields to match (source and destination IPs) */
760+
static const uint8_t raw_pattern_mask[] = {
761+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC addresses - ignored */
762+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
763+
0x00, 0x00, /* EtherType - ignored */
764+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
765+
0x00, 0x00, 0x00, 0x00, /* IPv4/UDP headers - ignored */
766+
0xff, 0xff, 0xff, 0xff, /* Source IP - match all bits */
767+
0xff, 0xff, 0xff, 0xff, /* Destination IP - match all bits */
768+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* UDP - ignored */
769+
};
770+
771+
struct rte_flow_item_raw raw_spec = {
772+
.length = sizeof(raw_pattern_spec),
773+
.pattern = raw_pattern_spec,
774+
};
775+
776+
struct rte_flow_item_raw raw_mask = {
777+
.length = sizeof(raw_pattern_mask),
778+
.pattern = raw_pattern_mask,
779+
};
780+
781+
struct rte_flow_attr attr = {
782+
.ingress = 1,
783+
};
784+
785+
struct rte_flow_item pattern[] = {
786+
{
787+
.type = RTE_FLOW_ITEM_TYPE_RAW,
788+
.spec = &raw_spec,
789+
.mask = &raw_mask,
790+
},
791+
{
792+
.type = RTE_FLOW_ITEM_TYPE_END,
793+
},
794+
};
795+
796+
struct rte_flow_action actions[] = {
797+
/* direct flow to queue index 3 */
798+
{
799+
.type = RTE_FLOW_ACTION_TYPE_QUEUE,
800+
.conf = &(struct rte_flow_action_queue){ .index = 3 },
801+
},
802+
/* write id into mbuf FDIR metadata */
803+
{
804+
.type = RTE_FLOW_ACTION_TYPE_MARK,
805+
.conf = &(struct rte_flow_action_mark){ .id = 3 },
806+
},
807+
{
808+
.type = RTE_FLOW_ACTION_TYPE_END,
809+
},
810+
};
811+
812+
struct rte_flow_error error;
813+
struct rte_flow *flow = flow = rte_flow_create(port_id, &attr, pattern, actions, &error);
814+
815+
To use masked bits (IPv4 source/destination addresses) to distribute such packets via RSS:
816+
817+
.. code-block:: console
818+
819+
flow create 0 ingress pattern raw \
820+
pattern spec 00000000000100000000000208004500001c000000000011000001010101020202020000000000080000 \
821+
pattern mask 0000000000000000000000000000000000000000000000000000ffffffffffffffff0000000000000000 / end \
822+
actions rss / end
823+
824+
Equivalent C code using the rte_flow API:
825+
826+
.. code-block:: c
827+
828+
/* Use the same structures and code as above, only actions change */
829+
830+
struct rte_flow_action actions[] = {
831+
{
832+
.type = RTE_FLOW_ACTION_TYPE_RSS,
833+
/* Use NULL conf for default RSS configuration */
834+
},
835+
{
836+
.type = RTE_FLOW_ACTION_TYPE_END,
837+
},
838+
};
839+
840+
**Limitations**
638841

639842
Currently, raw pattern support is limited to the FDIR and Hash engines.
640843

844+
.. note::
845+
846+
**DDP Package Dependency**: Raw pattern functionality relies on the loaded DDP package to define available packet types and protocol parsing rules.
847+
Different DDP packages (OS Default, COMMS, Wireless) may support different protocol combinations and PTYPE mappings.
848+
641849
Traffic Management Support
642850
~~~~~~~~~~~~~~~~~~~~~~~~~~
643851

0 commit comments

Comments
 (0)