Steering by Packet Type
The new RTE flow item RTE_FLOW_ITEM_TYPE_PTYPE provides a quick way of finding out L2/L3/L4 protocols in each packet. This helps with optimized flow rules matching, eliminating the need of stacking all the packet headers in the matching criteria.
The supported values are:
L2: ``RTE_PTYPE_L2_ETHER``, ``RTE_PTYPE_L2_ETHER_VLAN``, ``RTE_PTYPE_L2_ETHER_QINQ``
L3: ``RTE_PTYPE_L3_IPV4``, ``RTE_PTYPE_L3_IPV6``
L4: ``RTE_PTYPE_L4_TCP``, ``RTE_PTYPE_L4_UDP``, ``RTE_PTYPE_L4_ICMP``
and their ``RTE_PTYPE_INNER_XXX`` counterparts as well as ``RTE_PTYPE_TUNNEL_ESP``.
Matching on both outer and inner IP fragmented is supported using ``RTE_PTYPE_L4_FRAG`` and
RTE_PTYPE_INNER_L4_FRAG`` values. They are not part of L4 types, so they should be provided as a mask value during pattern template creation explicitly.
Match on outer IPv4 and ICMP.
# RTE_PTYPE_L4_TCP / RTE_PTYPE_L4_MASK
flow pattern_template 0
create pattern_template_id 1
ingress template ptype packet_type is 0x510
packet_type mask 0xff0
/ end
flow actions_template 0
create actions_template_id 1
template queue / end mask queue / end
flow template_table 0
create table_id 1
group 1
priority 0
ingress rules_number 64
pattern_template 1
actions_template 1
flow queue 0
create 0
template_table 1
pattern_template 0
actions_template 0
postpone no pattern ptype packet_type is 0x510
/ end actions queue index 1
/ end
static
int
add_ptype_items(void
) {
struct rte_flow_action_queue queue = { .index = rx_q };
struct rte_flow_item_ptype ptype_spec =
{.packet_type = 0x510
};
struct rte_flow_item_integrity ptype_mask =
{.packet_type = 0xff0
};
int
res;
memset(pattern, 0
, sizeof(pattern));
memset(action, 0
, sizeof(action));
/*
* set the rule attribute.
* in this case only ingress packets will be checked.
*/
memset(&attr, 0
, sizeof(struct rte_flow_attr));
attr.ingress = 1
;
/*
* create the action sequence.
* one action only, move packet to queue
*/
action[0
].type = RTE_FLOW_ACTION_TYPE_QUEUE;
action[0
].conf = &queue;
action[1
].type = RTE_FLOW_ACTION_TYPE_END;
/*
* match on RTE_PTYPE_L4_TCP / RTE_PTYPE_L4_MASK
*/
pattern[0
].type = RTE_FLOW_ITEM_TYPE_PTYPE;
pattern[0
].spec = &ptype_mask;
pattern[0
].mask = &ptype_spec;
/* the final level must be always type end */
pattern[1
].type = RTE_FLOW_ITEM_TYPE_END;
}