1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef _RTE_FLOW_CLASSIFY_H_
6 #define _RTE_FLOW_CLASSIFY_H_
11 * RTE Flow Classify Library
13 * @b EXPERIMENTAL: this API may change without prior notice
15 * This library provides flow record information with some measured properties.
17 * Application should define the flow and measurement criteria (action) for it.
19 * The Library doesn't maintain any flow records itself, instead flow
20 * information is returned to upper layer only for given packets.
22 * It is application's responsibility to call rte_flow_classifier_query()
23 * for a burst of packets, just after receiving them or before transmitting
25 * Application should provide the flow type interested in, measurement to apply
26 * to that flow in rte_flow_classify_table_entry_add() API, and should provide
27 * the rte_flow_classifier object and storage to put results in for the
28 * rte_flow_classifier_query() API.
31 * - application calls rte_flow_classifier_create() to create an
32 * rte_flow_classifier object.
33 * - application calls rte_flow_classify_table_create() to create a table
34 * in the rte_flow_classifier object.
35 * - application calls rte_flow_classify_table_entry_add() to add a rule to
36 * the table in the rte_flow_classifier object.
37 * - application calls rte_flow_classifier_query() in a polling manner,
38 * preferably after rte_eth_rx_burst(). This will cause the library to
39 * match packet information to flow information with some measurements.
40 * - rte_flow_classifier object can be destroyed when it is no longer needed
41 * with rte_flow_classifier_free()
44 #include <rte_common.h>
45 #include <rte_ethdev.h>
46 #include <rte_ether.h>
49 #include <rte_table_acl.h>
55 extern int librte_flow_classify_logtype;
57 #define RTE_FLOW_CLASSIFY_LOG(level, ...) \
58 rte_log(RTE_LOG_ ## level, \
59 librte_flow_classify_logtype, \
60 RTE_FMT("%s(): " RTE_FMT_HEAD(__VA_ARGS__,), \
62 RTE_FMT_TAIL(__VA_ARGS__,)))
64 #ifndef RTE_FLOW_CLASSIFY_TABLE_MAX
65 #define RTE_FLOW_CLASSIFY_TABLE_MAX 32
68 /** Opaque data type for flow classifier */
69 struct rte_flow_classifier;
71 /** Opaque data type for flow classify rule */
72 struct rte_flow_classify_rule;
74 /** Flow classify rule type */
75 enum rte_flow_classify_rule_type {
77 RTE_FLOW_CLASSIFY_RULE_TYPE_NONE,
78 /** IPv4 5tuple type */
79 RTE_FLOW_CLASSIFY_RULE_TYPE_IPV4_5TUPLE,
82 /** Flow classify table type */
83 enum rte_flow_classify_table_type {
85 RTE_FLOW_CLASSIFY_TABLE_TYPE_NONE = 1 << 0,
87 RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE = 1 << 1,
88 /** ACL VLAN IP4 5TUPLE */
89 RTE_FLOW_CLASSIFY_TABLE_ACL_VLAN_IP4_5TUPLE = 1 << 2,
90 /** ACL QinQ IP4 5TUPLE */
91 RTE_FLOW_CLASSIFY_TABLE_ACL_QINQ_IP4_5TUPLE = 1 << 3,
95 /** Parameters for flow classifier creation */
96 struct rte_flow_classifier_params {
97 /** flow classifier name */
100 /** CPU socket ID where memory for the flow classifier and its */
101 /** elements (tables) should be allocated */
105 /** Parameters for table creation */
106 struct rte_flow_classify_table_params {
107 /** Table operations (specific to each table type) */
108 struct rte_table_ops *ops;
110 /** Opaque param to be passed to the table create operation */
113 /** Classifier table type */
114 enum rte_flow_classify_table_type type;
117 /** IPv4 5-tuple data */
118 struct rte_flow_classify_ipv4_5tuple {
119 uint32_t dst_ip; /**< Destination IP address in big endian. */
120 uint32_t dst_ip_mask; /**< Mask of destination IP address. */
121 uint32_t src_ip; /**< Source IP address in big endian. */
122 uint32_t src_ip_mask; /**< Mask of destination IP address. */
123 uint16_t dst_port; /**< Destination port in big endian. */
124 uint16_t dst_port_mask; /**< Mask of destination port. */
125 uint16_t src_port; /**< Source Port in big endian. */
126 uint16_t src_port_mask; /**< Mask of source port. */
127 uint8_t proto; /**< L4 protocol. */
128 uint8_t proto_mask; /**< Mask of L4 protocol. */
134 * For the count action, stats can be returned by the query API.
136 * Storage for stats is provided by application.
138 struct rte_flow_classify_stats {
142 struct rte_flow_classify_ipv4_5tuple_stats {
143 /** count of packets that match IPv4 5tuple pattern */
145 /** IPv4 5tuple data */
146 struct rte_flow_classify_ipv4_5tuple ipv4_5tuple;
150 * Flow classifier create
153 * Parameters for flow classifier creation
155 * Handle to flow classifier instance on success or NULL otherwise
157 struct rte_flow_classifier *
158 rte_flow_classifier_create(struct rte_flow_classifier_params *params);
161 * Flow classifier free
164 * Handle to flow classifier instance
166 * 0 on success, error code otherwise
169 rte_flow_classifier_free(struct rte_flow_classifier *cls);
172 * Flow classify table create
175 * Handle to flow classifier instance
177 * Parameters for flow_classify table creation
179 * 0 on success, error code otherwise
182 rte_flow_classify_table_create(struct rte_flow_classifier *cls,
183 struct rte_flow_classify_table_params *params);
186 * Flow classify validate
189 * Handle to flow classifier instance
191 * Flow rule attributes
193 * Pattern specification (list terminated by the END pattern item).
195 * Associated actions (list terminated by the END pattern item).
197 * Perform verbose error reporting if not NULL. Structure
198 * initialised in case of error only.
200 * 0 on success, error code otherwise
203 rte_flow_classify_validate(struct rte_flow_classifier *cls,
204 const struct rte_flow_attr *attr,
205 const struct rte_flow_item pattern[],
206 const struct rte_flow_action actions[],
207 struct rte_flow_error *error);
210 * Add a flow classify rule to the flow_classifer table.
213 * Flow classifier handle
215 * Flow rule attributes
217 * Pattern specification (list terminated by the END pattern item).
219 * Associated actions (list terminated by the END pattern item).
220 * @param[out] key_found
221 * returns 1 if rule present already, 0 otherwise.
223 * Perform verbose error reporting if not NULL. Structure
224 * initialised in case of error only.
226 * A valid handle in case of success, NULL otherwise.
228 struct rte_flow_classify_rule *
229 rte_flow_classify_table_entry_add(struct rte_flow_classifier *cls,
230 const struct rte_flow_attr *attr,
231 const struct rte_flow_item pattern[],
232 const struct rte_flow_action actions[],
234 struct rte_flow_error *error);
237 * Delete a flow classify rule from the flow_classifer table.
240 * Flow classifier handle
244 * 0 on success, error code otherwise.
247 rte_flow_classify_table_entry_delete(struct rte_flow_classifier *cls,
248 struct rte_flow_classify_rule *rule);
251 * Query flow classifier for given rule.
254 * Flow classifier handle
256 * Pointer to packets to process
258 * Number of packets to process
262 * Flow classify stats
265 * 0 on success, error code otherwise.
268 rte_flow_classifier_query(struct rte_flow_classifier *cls,
269 struct rte_mbuf **pkts,
270 const uint16_t nb_pkts,
271 struct rte_flow_classify_rule *rule,
272 struct rte_flow_classify_stats *stats);
278 #endif /* _RTE_FLOW_CLASSIFY_H_ */