Flexible Item
For the usage example please refer to: http://doc.dpdk.org/guides/testpmd_app_ug/testpmd_funcs.html, section "Flex Item Functions".
Code Snippets
Take eCPRI header as an example:
const
struct rte_flow_item_flex_conf ecpri_flex_conf = {
/* single eCPRI header in a packet. Can be ether inner or outer */
.tunnel = FLEX_TUNNEL_MODE_SINGLE,
/* eCPRI header size description */
.next_header = {
.field_mode = FIELD_MODE_FIXED, /* fixed-size header */
.field_size = 4
* sizeof(char
) * CHAR_BIT;
},
/* eCPRI header is followed by a payload */
.next_protocol = {},
/* single sample that covers entire eCPRI header */
.sample_data = {
{
.field_mode = FIELD_MODE_FIXED,
.field_size = 4
* sizeof(char
) * CHAR_BIT,
.field_base = 0
}
},
.nb_samples = 1
,
/* eCPRI protocol follows ether Ethernet or UDP headers */
.input_link = {
{
.item = {
.type = RTE_FLOW_ITEM_TYPE_ETH,
.spec = &(struct rte_flow_item_eth) {
.type = rte_cpu_to_be_16(0xAEFE
),
},
}
},
{
.item = {
.type = RTE_FLOW_ITEM_TYPE_UDP,
.spec = &(struct rte_flow_item_udp) {
.hdr.dst_port = rte_cpu_to_be_16(0xAEFE
)
},
}
},
},
.nb_inputs = 2
,
/* no network protocol follows eCPRI header */
.nb_outputs = 0
;
};
struct rte_flow_item_flex_handle *ecpri_flex_handle;
ecpri_flex_handle = rte_flow_flex_item_create(port_id, ecpri_flex_conf, error);
// Match Type #3 Generic Data Transfer
const
struct ecpri_hdr ecpri_data_transfer_spec = {
.version = 1
,
.msg_type = 3
};
const
struct ecpri_hdr ecpri_data_transfer_mask = {
.version = 0xf
,
.msg_type = 0xff
};
const
struct rte_flow_item_flex ecpri_data_transfer_flex_spec = {
.handle = ecpri_flex_handle,
.length = sizeof(ecpri_data_transfer_spec),
.pattern = &ecpri_data_transfer_spec
};
const
struct rte_flow_item_flex ecpri_data_transfer_flex_mask = {
.handle = ecpri_flex_handle,
.length = sizeof(ecpri_data_transfer_mask),
.pattern = &ecpri_data_transfer_mask
};
const
struct rte_flow_item ecpri_data_transfer_flow_item = {
.type = RTE_FLOW_ITEM_TYPE_FLEX,
.spec = (const
void
*)&ecpri_data_transfer_flex_spec,
.mask = (const
void
*)&ecpri_data_transfer_flex_mask,
};