4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _RTE_FLOW_CLASSIFY_H_
35 #define _RTE_FLOW_CLASSIFY_H_
40 * RTE Flow Classify Library
42 * @b EXPERIMENTAL: this API may change without prior notice
44 * This library provides flow record information with some measured properties.
46 * Application should define the flow and measurement criteria (action) for it.
48 * The Library doesn't maintain any flow records itself, instead flow
49 * information is returned to upper layer only for given packets.
51 * It is application's responsibility to call rte_flow_classifier_query()
52 * for a burst of packets, just after receiving them or before transmitting
54 * Application should provide the flow type interested in, measurement to apply
55 * to that flow in rte_flow_classify_table_entry_add() API, and should provide
56 * the rte_flow_classifier object and storage to put results in for the
57 * rte_flow_classifier_query() API.
60 * - application calls rte_flow_classifier_create() to create an
61 * rte_flow_classifier object.
62 * - application calls rte_flow_classify_table_create() to create a table
63 * in the rte_flow_classifier object.
64 * - application calls rte_flow_classify_table_entry_add() to add a rule to
65 * the table in the rte_flow_classifier object.
66 * - application calls rte_flow_classifier_query() in a polling manner,
67 * preferably after rte_eth_rx_burst(). This will cause the library to
68 * match packet information to flow information with some measurements.
69 * - rte_flow_classifier object can be destroyed when it is no longer needed
70 * with rte_flow_classifier_free()
73 #include <rte_ethdev.h>
74 #include <rte_ether.h>
77 #include <rte_table_acl.h>
83 extern int librte_flow_classify_logtype;
85 #define RTE_FLOW_CLASSIFY_LOG(level, fmt, args...) \
86 rte_log(RTE_LOG_ ## level, librte_flow_classify_logtype, "%s(): " fmt, \
89 /** Opaque data type for flow classifier */
90 struct rte_flow_classifier;
92 /** Opaque data type for flow classify rule */
93 struct rte_flow_classify_rule;
95 /** Flow classify rule type */
96 enum rte_flow_classify_rule_type {
98 RTE_FLOW_CLASSIFY_RULE_TYPE_NONE,
99 /** IPv4 5tuple type */
100 RTE_FLOW_CLASSIFY_RULE_TYPE_IPV4_5TUPLE,
103 /** Flow classify table type */
104 enum rte_flow_classify_table_type {
106 RTE_FLOW_CLASSIFY_TABLE_TYPE_NONE,
108 RTE_FLOW_CLASSIFY_TABLE_TYPE_ACL,
112 * Maximum number of tables allowed for any Flow Classifier instance.
113 * The value of this parameter cannot be changed.
115 #define RTE_FLOW_CLASSIFY_TABLE_MAX 64
117 /** Parameters for flow classifier creation */
118 struct rte_flow_classifier_params {
119 /** flow classifier name */
122 /** CPU socket ID where memory for the flow classifier and its */
123 /** elements (tables) should be allocated */
127 enum rte_flow_classify_table_type type;
130 /** Parameters for table creation */
131 struct rte_flow_classify_table_params {
132 /** Table operations (specific to each table type) */
133 struct rte_table_ops *ops;
135 /** Opaque param to be passed to the table create operation */
139 /** IPv4 5-tuple data */
140 struct rte_flow_classify_ipv4_5tuple {
141 uint32_t dst_ip; /**< Destination IP address in big endian. */
142 uint32_t dst_ip_mask; /**< Mask of destination IP address. */
143 uint32_t src_ip; /**< Source IP address in big endian. */
144 uint32_t src_ip_mask; /**< Mask of destination IP address. */
145 uint16_t dst_port; /**< Destination port in big endian. */
146 uint16_t dst_port_mask; /**< Mask of destination port. */
147 uint16_t src_port; /**< Source Port in big endian. */
148 uint16_t src_port_mask; /**< Mask of source port. */
149 uint8_t proto; /**< L4 protocol. */
150 uint8_t proto_mask; /**< Mask of L4 protocol. */
156 * For the count action, stats can be returned by the query API.
158 * Storage for stats is provided by application.
160 struct rte_flow_classify_stats {
164 struct rte_flow_classify_ipv4_5tuple_stats {
165 /** count of packets that match IPv4 5tuple pattern */
167 /** IPv4 5tuple data */
168 struct rte_flow_classify_ipv4_5tuple ipv4_5tuple;
172 * Flow classifier create
175 * Parameters for flow classifier creation
177 * Handle to flow classifier instance on success or NULL otherwise
179 struct rte_flow_classifier *
180 rte_flow_classifier_create(struct rte_flow_classifier_params *params);
183 * Flow classifier free
186 * Handle to flow classifier instance
188 * 0 on success, error code otherwise
191 rte_flow_classifier_free(struct rte_flow_classifier *cls);
194 * Flow classify table create
197 * Handle to flow classifier instance
199 * Parameters for flow_classify table creation
201 * Table ID. Valid only within the scope of table IDs of the current
202 * classifier. Only returned after a successful invocation.
204 * 0 on success, error code otherwise
207 rte_flow_classify_table_create(struct rte_flow_classifier *cls,
208 struct rte_flow_classify_table_params *params,
212 * Add a flow classify rule to the flow_classifer table.
215 * Flow classifier handle
216 * @param[in] table_id
218 * @param[out] key_found
219 * returns 1 if key present already, 0 otherwise.
221 * Flow rule attributes
223 * Pattern specification (list terminated by the END pattern item).
225 * Associated actions (list terminated by the END pattern item).
227 * Perform verbose error reporting if not NULL. Structure
228 * initialised in case of error only.
230 * A valid handle in case of success, NULL otherwise.
232 struct rte_flow_classify_rule *
233 rte_flow_classify_table_entry_add(struct rte_flow_classifier *cls,
236 const struct rte_flow_attr *attr,
237 const struct rte_flow_item pattern[],
238 const struct rte_flow_action actions[],
239 struct rte_flow_error *error);
242 * Delete a flow classify rule from the flow_classifer table.
245 * Flow classifier handle
246 * @param[in] table_id
251 * 0 on success, error code otherwise.
254 rte_flow_classify_table_entry_delete(struct rte_flow_classifier *cls,
256 struct rte_flow_classify_rule *rule);
259 * Query flow classifier for given rule.
262 * Flow classifier handle
263 * @param[in] table_id
266 * Pointer to packets to process
268 * Number of packets to process
272 * Flow classify stats
275 * 0 on success, error code otherwise.
278 rte_flow_classifier_query(struct rte_flow_classifier *cls,
280 struct rte_mbuf **pkts,
281 const uint16_t nb_pkts,
282 struct rte_flow_classify_rule *rule,
283 struct rte_flow_classify_stats *stats);
289 #endif /* _RTE_FLOW_CLASSIFY_H_ */