ethdev: introduce configurable flexible item

1. Introduction and Retrospective

Nowadays the networks are evolving fast and wide, the network
structures are getting more and more complicated, the new
application areas are emerging. To address these challenges
the new network protocols are continuously being developed,
considered by technical communities, adopted by industry and,
eventually implemented in hardware and software. The DPDK
framework follows the common trends and if we bother
to glance at the RTE Flow API header we see the multiple
new items were introduced during the last years since
the initial release.

The new protocol adoption and implementation process is
not straightforward and takes time, the new protocol passes
development, consideration, adoption, and implementation
phases. The industry tries to mitigate and address the
forthcoming network protocols, for example, many hardware
vendors are implementing flexible and configurable network
protocol parsers. As DPDK developers, could we anticipate
the near future in the same fashion and introduce the similar
flexibility in RTE Flow API?

Let's check what we already have merged in our project, and
we see the nice raw item (rte_flow_item_raw). At the first
glance, it looks superior and we can try to implement a flow
matching on the header of some relatively new tunnel protocol,
say on the GENEVE header with variable length options. And,
under further consideration, we run into the raw item
limitations:

- only fixed size network header can be represented
- the entire network header pattern of fixed format
  (header field offsets are fixed) must be provided
- the search for patterns is not robust (the wrong matches
  might be triggered), and actually is not supported
  by existing PMDs
- no explicitly specified relations with preceding
  and following items
- no tunnel hint support

As the result, implementing the support for tunnel protocols
like aforementioned GENEVE with variable extra protocol option
with flow raw item becomes very complicated and would require
multiple flows and multiple raw items chained in the same
flow (by the way, there is no support found for chained raw
items in implemented drivers).

This RFC introduces the dedicated flex item (rte_flow_item_flex)
to handle matches with existing and new network protocol headers
in a unified fashion.

2. Flex Item Life Cycle

Let's assume there are the requirements to support the new
network protocol with RTE Flows. What is given within protocol
specification:

  - header format
  - header length, (can be variable, depending on options)
  - potential presence of extra options following or included
    in the header the header
  - the relations with preceding protocols. For example,
    the GENEVE follows UDP, eCPRI can follow either UDP
    or L2 header
  - the relations with following protocols. For example,
    the next layer after tunnel header can be L2 or L3
  - whether the new protocol is a tunnel and the header
    is a splitting point between outer and inner layers

The supposed way to operate with flex item:

  - application defines the header structures according to
    protocol specification

  - application calls rte_flow_flex_item_create() with desired
    configuration according to the protocol specification, it
    creates the flex item object over specified ethernet device
    and prepares PMD and underlying hardware to handle flex
    item. On item creation call PMD backing the specified
    ethernet device returns the opaque handle identifying
    the object has been created

  - application uses the rte_flow_item_flex with obtained handle
    in the flows, the values/masks to match with fields in the
    header are specified in the flex item per flow as for regular
    items (except that pattern buffer combines all fields)

  - flows with flex items match with packets in a regular fashion,
    the values and masks for the new protocol header match are
    taken from the flex items in the flows

  - application destroys flows with flex items

  - application calls rte_flow_flex_item_release() as part of
    ethernet device API and destroys the flex item object in
    PMD and releases the engaged hardware resources

3. Flex Item Structure

The flex item structure is intended to be used as part of the flow
pattern like regular RTE flow items and provides the mask and
value to match with fields of the protocol item was configured
for.

  struct rte_flow_item_flex {
    void *handle;
    uint32_t length;
    const uint8_t* pattern;
  };

The handle is some opaque object maintained on per device basis
by underlying driver.

The protocol header fields are considered as bit fields, all
offsets and widths are expressed in bits. The pattern is the
buffer containing the bit concatenation of all the fields
presented at item configuration time, in the same order and
same amount. If byte boundary alignment is needed an application
can use a dummy type field, this is just some kind of gap filler.

The length field specifies the pattern buffer length in bytes
and is needed to allow rte_flow_copy() operations. The approach
of multiple pattern pointers and lengths (per field) was
considered and found clumsy - it seems to be much suitable for
the application to maintain the single structure within the
single pattern buffer.

4. Flex Item Configuration

The flex item configuration consists of the following parts:

  - header field descriptors:
    - next header
    - next protocol
    - sample to match
  - input link descriptors
  - output link descriptors

The field descriptors tell the driver and hardware what data should
be extracted from the packet and then control the packet handling
in the flow engine. Besides this, sample fields can be presented
to match with patterns in the flows. Each field is a bit pattern.
It has width, offset from the header beginning, mode of offset
calculation, and offset related parameters.

The next header field is special, no data are actually taken
from the packet, but its offset is used as a pointer to the next
header in the packet, in other words the next header offset
specifies the size of the header being parsed by flex item.

There is one more special field - next protocol, it specifies
where the next protocol identifier is contained and packet data
sampled from this field will be used to determine the next
protocol header type to continue packet parsing. The next
protocol field is like eth_type field in MAC2, or proto field
in IPv4/v6 headers.

The sample fields are used to represent the data be sampled
from the packet and then matched with established flows.

There are several methods supposed to calculate field offset
in runtime depending on configuration and packet content:

  - FIELD_MODE_FIXED - fixed offset. The bit offset from
    header beginning is permanent and defined by field_base
    configuration parameter.

  - FIELD_MODE_OFFSET - the field bit offset is extracted
    from other header field (indirect offset field). The
    resulting field offset to match is calculated from as:

  field_base + (*offset_base & offset_mask) << offset_shift

    This mode is useful to sample some extra options following
    the main header with field containing main header length.
    Also, this mode can be used to calculate offset to the
    next protocol header, for example - IPv4 header contains
    the 4-bit field with IPv4 header length expressed in dwords.
    One more example - this mode would allow us to skip GENEVE
    header variable length options.

  - FIELD_MODE_BITMASK - the field bit offset is extracted
    from other header field (indirect offset field), the latter
    is considered as bitmask containing some number of one bits,
    the resulting field offset to match is calculated as:

  field_base + bitcount(*offset_base & offset_mask) << offset_shift

    This mode would be useful to skip the GTP header and its
    extra options with specified flags.

  - FIELD_MODE_DUMMY - dummy field, optionally used for byte
    boundary alignment in pattern. Pattern mask and data are
    ignored in the match. All configuration parameters besides
    field size and offset are ignored.

  Note:  "*" - means the indirect field offset is calculated
  and actual data are extracted from the packet by this
  offset (like data are fetched by pointer *p from memory).

The offset mode list can be extended by vendors according to
hardware supported options.

The input link configuration section tells the driver after
what protocols and at what conditions the flex item can follow.
Input link specified the preceding header pattern, for example
for GENEVE it can be UDP item specifying match on destination
port with value 6081. The flex item can follow multiple header
types and multiple input links should be specified. At flow
creation time the item with one of the input link types should
precede the flex item and driver will select the correct flex
item settings, depending on the actual flow pattern.

The output link configuration section tells the driver how
to continue packet parsing after the flex item protocol.
If multiple protocols can follow the flex item header the
flex item should contain the field with the next protocol
identifier and the parsing will be continued depending
on the data contained in this field in the actual packet.

The flex item fields can participate in RSS hash calculation,
the dedicated flag is present in the field description to specify
what fields should be provided for hashing.

5. Flex Item Chaining

If there are multiple protocols supposed to be supported with
flex items in chained fashion - two or more flex items within
the same flow and these ones might be neighbors in the pattern,
it means the flex items are mutual referencing.  In this case,
the item that occurred first should be created with empty
output link list or with the list including existing items,
and then the second flex item should be created referencing
the first flex item as input arc, drivers should adjust
the item configuration.

Also, the hardware resources used by flex items to handle
the packet can be limited. If there are multiple flex items
that are supposed to be used within the same flow it would
be nice to provide some hint for the driver that these two
or more flex items are intended for simultaneous usage.
The fields of items should be assigned with hint indices
and these indices from two or more flex items supposed
to be provided within the same flow should be the same
as well. In other words, the field hint index specifies
the group of fields that can be matched simultaneously
within a single flow. If hint indices are specified,
the driver will try to engage not overlapping hardware
resources and provide independent handling of the field
groups with unique indices. If the hint index is zero
the driver assigns resources on its own.

6. Example of New Protocol Handling

Let's suppose we have the requirements to handle the new tunnel
protocol that follows UDP header with destination port 0xFADE
and is followed by MAC header. Let the new protocol header format
be like this:

  struct new_protocol_header {
    rte_be32 header_length; /* length in dwords, including options */
    rte_be32 specific0;     /* some protocol data, no intention */
    rte_be32 specific1;     /* to match in flows on these fields */
    rte_be32 crucial;       /* data of interest, match is needed */
    rte_be32 options[0];    /* optional protocol data, variable length */
  };

The supposed flex item configuration:

  struct rte_flow_item_flex_field field0 = {
    .field_mode = FIELD_MODE_DUMMY,  /* Affects match pattern only */
    .field_size = 96,                /* three dwords from the beginning */
  };
  struct rte_flow_item_flex_field field1 = {
    .field_mode = FIELD_MODE_FIXED,
    .field_size = 32,       /* Field size is one dword */
    .field_base = 96,       /* Skip three dwords from the beginning */
  };
  struct rte_flow_item_udp spec0 = {
    .hdr = {
      .dst_port = RTE_BE16(0xFADE),
    }
  };
  struct rte_flow_item_udp mask0 = {
    .hdr = {
      .dst_port = RTE_BE16(0xFFFF),
    }
  };
  struct rte_flow_item_flex_link link0 = {
    .item = {
       .type = RTE_FLOW_ITEM_TYPE_UDP,
       .spec = &spec0,
       .mask = &mask0,
  };

  struct rte_flow_item_flex_conf conf = {
    .next_header = {
      .tunnel = FLEX_TUNNEL_MODE_SINGLE,
      .field_mode = FIELD_MODE_OFFSET,
      .field_base = 0,
      .offset_base = 0,
      .offset_mask = 0xFFFFFFFF,
      .offset_shift = 2	   /* Expressed in dwords, shift left by 2 */
    },
    .sample = {
       &field0,
       &field1,
    },
    .nb_samples = 2,
    .input_link[0] = &link0,
    .nb_inputs = 1
  };

Let's suppose we have created the flex item successfully, and PMD
returned the handle 0x123456789A. We can use the following item
pattern to match the crucial field in the packet with value 0x00112233:

  struct new_protocol_header spec_pattern =
  {
    .crucial = RTE_BE32(0x00112233),
  };
  struct new_protocol_header mask_pattern =
  {
    .crucial = RTE_BE32(0xFFFFFFFF),
  };
  struct rte_flow_item_flex spec_flex = {
    .handle = 0x123456789A
    .length = sizeiof(struct new_protocol_header),
    .pattern = &spec_pattern,
  };
  struct rte_flow_item_flex mask_flex = {
    .length = sizeof(struct new_protocol_header),
    .pattern = &mask_pattern,
  };
  struct rte_flow_item item_to_match = {
    .type = RTE_FLOW_ITEM_TYPE_FLEX,
    .spec = &spec_flex,
    .mask = &mask_flex,
  };

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Acked-by: Ori Kam <orika@nvidia.com>
This commit is contained in:
Viacheslav Ovsiienko 2021-10-20 18:14:55 +03:00 committed by Ferruh Yigit
parent 6cf7204733
commit dc4d860e8a
6 changed files with 322 additions and 0 deletions

View File

@ -1548,6 +1548,31 @@ This item is meant to use the same structure as `Item: PORT_REPRESENTOR`_.
See also `Action: REPRESENTED_PORT`_.
Item: ``FLEX``
^^^^^^^^^^^^^^
Matches with the custom network protocol header that was created
using rte_flow_flex_item_create() API. The application describes
the desired header structure, defines the header fields attributes
and header relations with preceding and following protocols and
configures the ethernet devices accordingly via
rte_flow_flex_item_create() routine.
- ``handle``: the flex item handle returned by the PMD on successful
rte_flow_flex_item_create() call, mask for this field is ignored.
- ``length``: match pattern length in bytes. If the length does not cover
all fields defined in item configuration, the pattern spec and mask are
considered by the driver as padded with trailing zeroes till the full
configured item pattern length.
- ``pattern``: pattern to match. The pattern is concatenation of bit fields
configured at item creation. At configuration the fields are presented
by sample_data array. The order of the bitfields is defined by the order
of sample_data elements. The width of each bitfield is defined by the width
specified in the corresponding sample_data element as well. If pattern
length is smaller than configured fields overall length it is considered
as padded with trailing zeroes up to full configured length, both for
value and mask.
Actions
~~~~~~~

View File

@ -85,6 +85,13 @@ New Features
Added macros ETH_RSS_IPV4_CHKSUM and ETH_RSS_L4_CHKSUM, now IPv4 and
TCP/UDP/SCTP header checksum field can be used as input set for RSS.
* **Added flow flex item.**
The configurable flow flex item provides the capability to introduce
an arbitrary user-specified network protocol header,
configure the hardware accordingly, and perform match on this header
with desired patterns and masks.
* **Added ethdev support to control delivery of Rx metadata from the HW to the PMD.**
A new API, ``rte_eth_rx_metadata_negotiate()``, was added.

View File

@ -63,6 +63,19 @@ rte_flow_conv_copy(void *buf, const void *data, const size_t size,
return sz;
}
static size_t
rte_flow_item_flex_conv(void *buf, const void *data)
{
struct rte_flow_item_flex *dst = buf;
const struct rte_flow_item_flex *src = data;
if (buf) {
dst->pattern = rte_memcpy
((void *)((uintptr_t)(dst + 1)), src->pattern,
src->length);
}
return src->length;
}
/** Generate flow_item[] entry. */
#define MK_FLOW_ITEM(t, s) \
[RTE_FLOW_ITEM_TYPE_ ## t] = { \
@ -141,6 +154,8 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = {
MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)),
MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)),
MK_FLOW_ITEM(REPRESENTED_PORT, sizeof(struct rte_flow_item_ethdev)),
MK_FLOW_ITEM_FN(FLEX, sizeof(struct rte_flow_item_flex),
rte_flow_item_flex_conv),
};
/** Generate flow_action[] entry. */
@ -1332,3 +1347,43 @@ rte_flow_pick_transfer_proxy(uint16_t port_id, uint16_t *proxy_port_id,
ops->pick_transfer_proxy(dev, proxy_port_id, error),
error);
}
struct rte_flow_item_flex_handle *
rte_flow_flex_item_create(uint16_t port_id,
const struct rte_flow_item_flex_conf *conf,
struct rte_flow_error *error)
{
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
struct rte_flow_item_flex_handle *handle;
if (unlikely(!ops))
return NULL;
if (unlikely(!ops->flex_item_create)) {
rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
NULL, rte_strerror(ENOTSUP));
return NULL;
}
handle = ops->flex_item_create(dev, conf, error);
if (handle == NULL)
flow_err(port_id, -rte_errno, error);
return handle;
}
int
rte_flow_flex_item_release(uint16_t port_id,
const struct rte_flow_item_flex_handle *handle,
struct rte_flow_error *error)
{
int ret;
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
if (unlikely(!ops || !ops->flex_item_release))
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
NULL, rte_strerror(ENOTSUP));
ret = ops->flex_item_release(dev, handle, error);
return flow_err(port_id, ret, error);
}

View File

@ -635,6 +635,15 @@ enum rte_flow_item_type {
* @see struct rte_flow_item_ethdev
*/
RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
/**
* Matches a configured set of fields at runtime calculated offsets
* over the generic network header with variable length and
* flexible pattern
*
* @see struct rte_flow_item_flex.
*/
RTE_FLOW_ITEM_TYPE_FLEX,
};
/**
@ -1931,6 +1940,177 @@ struct rte_flow_item {
const void *mask; /**< Bit-mask applied to spec and last. */
};
/**
* @warning
* @b EXPERIMENTAL: this structure may change without prior notice
*
* RTE_FLOW_ITEM_TYPE_FLEX
*
* Matches a specified set of fields within the network protocol
* header. Each field is presented as set of bits with specified width, and
* bit offset from the header beginning.
*
* The pattern is concatenation of bit fields configured at item creation
* by rte_flow_flex_item_create(). At configuration the fields are presented
* by sample_data array.
*
* This type does not support ranges (struct rte_flow_item.last).
*/
struct rte_flow_item_flex {
struct rte_flow_item_flex_handle *handle; /**< Opaque item handle. */
uint32_t length; /**< Pattern length in bytes. */
const uint8_t *pattern; /**< Combined bitfields pattern to match. */
};
/**
* Field bit offset calculation mode.
*/
enum rte_flow_item_flex_field_mode {
/**
* Dummy field, used for byte boundary alignment in pattern.
* Pattern mask and data are ignored in the match. All configuration
* parameters besides field size are ignored.
*/
FIELD_MODE_DUMMY = 0,
/**
* Fixed offset field. The bit offset from header beginning
* is permanent and defined by field_base parameter.
*/
FIELD_MODE_FIXED,
/**
* The field bit offset is extracted from other header field (indirect
* offset field). The resulting field offset to match is calculated as:
*
* field_base + (*offset_base & offset_mask) << offset_shift
*/
FIELD_MODE_OFFSET,
/**
* The field bit offset is extracted from other header field (indirect
* offset field), the latter is considered as bitmask containing some
* number of one bits, the resulting field offset to match is
* calculated as:
*
* field_base + bitcount(*offset_base & offset_mask) << offset_shift
*/
FIELD_MODE_BITMASK,
};
/**
* Flex item field tunnel mode
*/
enum rte_flow_item_flex_tunnel_mode {
/**
* The protocol header can be present in the packet only once.
* No multiple flex item flow inclusions (for inner/outer) are allowed.
* No any relations with tunnel protocols are imposed. The drivers
* can optimize hardware resource usage to handle match on single flex
* item of specific type.
*/
FLEX_TUNNEL_MODE_SINGLE = 0,
/**
* Flex item presents outer header only.
*/
FLEX_TUNNEL_MODE_OUTER,
/**
* Flex item presents inner header only.
*/
FLEX_TUNNEL_MODE_INNER,
/**
* Flex item presents either inner or outer header. The driver
* handles as many multiple inners as hardware supports.
*/
FLEX_TUNNEL_MODE_MULTI,
/**
* Flex item presents tunnel protocol header.
*/
FLEX_TUNNEL_MODE_TUNNEL,
};
/**
*
* @warning
* @b EXPERIMENTAL: this structure may change without prior notice
*/
__extension__
struct rte_flow_item_flex_field {
/** Defines how match field offset is calculated over the packet. */
enum rte_flow_item_flex_field_mode field_mode;
uint32_t field_size; /**< Field size in bits. */
int32_t field_base; /**< Field offset in bits. */
uint32_t offset_base; /**< Indirect offset field offset in bits. */
uint32_t offset_mask; /**< Indirect offset field bit mask. */
int32_t offset_shift; /**< Indirect offset multiply factor. */
uint32_t field_id:16; /**< Device hint, for multiple items in flow. */
uint32_t reserved:16; /**< Reserved field. */
};
/**
* @warning
* @b EXPERIMENTAL: this structure may change without prior notice
*/
struct rte_flow_item_flex_link {
/**
* Preceding/following header. The item type must be always provided.
* For preceding one item must specify the header value/mask to match
* for the link be taken and start the flex item header parsing.
*/
struct rte_flow_item item;
/**
* Next field value to match to continue with one of the configured
* next protocols.
*/
uint32_t next;
};
/**
* @warning
* @b EXPERIMENTAL: this structure may change without prior notice
*/
struct rte_flow_item_flex_conf {
/**
* Specifies the flex item and tunnel relations and tells the PMD
* whether flex item can be used for inner, outer or both headers,
* or whether flex item presents the tunnel protocol itself.
*/
enum rte_flow_item_flex_tunnel_mode tunnel;
/**
* The next header offset, it presents the network header size covered
* by the flex item and can be obtained with all supported offset
* calculating methods (fixed, dedicated field, bitmask, etc).
*/
struct rte_flow_item_flex_field next_header;
/**
* Specifies the next protocol field to match with link next protocol
* values and continue packet parsing with matching link.
*/
struct rte_flow_item_flex_field next_protocol;
/**
* The fields will be sampled and presented for explicit match
* with pattern in the rte_flow_flex_item. There can be multiple
* fields descriptors, the number should be specified by nb_samples.
*/
struct rte_flow_item_flex_field *sample_data;
/** Number of field descriptors in the sample_data array. */
uint32_t nb_samples;
/**
* Input link defines the flex item relation with preceding
* header. It specified the preceding item type and provides pattern
* to match. The flex item will continue parsing and will provide the
* data to flow match in case if there is the match with one of input
* links.
*/
struct rte_flow_item_flex_link *input_link;
/** Number of link descriptors in the input link array. */
uint32_t nb_inputs;
/**
* Output link defines the next protocol field value to match and
* the following protocol header to continue packet parsing. Also
* defines the tunnel-related behaviour.
*/
struct rte_flow_item_flex_link *output_link;
/** Number of link descriptors in the output link array. */
uint32_t nb_outputs;
};
/**
* Action types.
*
@ -4477,6 +4657,51 @@ __rte_experimental
int
rte_flow_pick_transfer_proxy(uint16_t port_id, uint16_t *proxy_port_id,
struct rte_flow_error *error);
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
*
* Create the flex item with specified configuration over
* the Ethernet device.
*
* @param port_id
* Port identifier of Ethernet device.
* @param[in] conf
* Item configuration.
* @param[out] error
* Perform verbose error reporting if not NULL. PMDs initialize this
* structure in case of error only.
*
* @return
* Non-NULL opaque pointer on success, NULL otherwise and rte_errno is set.
*/
__rte_experimental
struct rte_flow_item_flex_handle *
rte_flow_flex_item_create(uint16_t port_id,
const struct rte_flow_item_flex_conf *conf,
struct rte_flow_error *error);
/**
* Release the flex item on the specified Ethernet device.
*
* @param port_id
* Port identifier of Ethernet device.
* @param[in] handle
* Handle of the item existing on the specified device.
* @param[out] error
* Perform verbose error reporting if not NULL. PMDs initialize this
* structure in case of error only.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
__rte_experimental
int
rte_flow_flex_item_release(uint16_t port_id,
const struct rte_flow_item_flex_handle *handle,
struct rte_flow_error *error);
#ifdef __cplusplus
}
#endif

View File

@ -144,6 +144,14 @@ struct rte_flow_ops {
(struct rte_eth_dev *dev,
uint16_t *proxy_port_id,
struct rte_flow_error *error);
struct rte_flow_item_flex_handle *(*flex_item_create)
(struct rte_eth_dev *dev,
const struct rte_flow_item_flex_conf *conf,
struct rte_flow_error *error);
int (*flex_item_release)
(struct rte_eth_dev *dev,
const struct rte_flow_item_flex_handle *handle,
struct rte_flow_error *error);
};
/**

View File

@ -252,6 +252,8 @@ EXPERIMENTAL {
rte_eth_dev_conf_get;
rte_eth_macaddrs_get;
rte_eth_rx_metadata_negotiate;
rte_flow_flex_item_create;
rte_flow_flex_item_release;
rte_flow_pick_transfer_proxy;
};