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_common.h>
74 #include <rte_ethdev.h>
75 #include <rte_ether.h>
78 #include <rte_table_acl.h>
84 extern int librte_flow_classify_logtype;
86 #define RTE_FLOW_CLASSIFY_LOG(level, ...) \
87 rte_log(RTE_LOG_ ## level, \
88 librte_flow_classify_logtype, \
89 RTE_FMT("%s(): " RTE_FMT_HEAD(__VA_ARGS__,), \
91 RTE_FMT_TAIL(__VA_ARGS__,)))
93 /** Opaque data type for flow classifier */
94 struct rte_flow_classifier;
96 /** Opaque data type for flow classify rule */
97 struct rte_flow_classify_rule;
99 /** Flow classify rule type */
100 enum rte_flow_classify_rule_type {
102 RTE_FLOW_CLASSIFY_RULE_TYPE_NONE,
103 /** IPv4 5tuple type */
104 RTE_FLOW_CLASSIFY_RULE_TYPE_IPV4_5TUPLE,
107 /** Flow classify table type */
108 enum rte_flow_classify_table_type {
110 RTE_FLOW_CLASSIFY_TABLE_TYPE_NONE,
112 RTE_FLOW_CLASSIFY_TABLE_TYPE_ACL,
116 * Maximum number of tables allowed for any Flow Classifier instance.
117 * The value of this parameter cannot be changed.
119 #define RTE_FLOW_CLASSIFY_TABLE_MAX 64
121 /** Parameters for flow classifier creation */
122 struct rte_flow_classifier_params {
123 /** flow classifier name */
126 /** CPU socket ID where memory for the flow classifier and its */
127 /** elements (tables) should be allocated */
131 enum rte_flow_classify_table_type type;
134 /** Parameters for table creation */
135 struct rte_flow_classify_table_params {
136 /** Table operations (specific to each table type) */
137 struct rte_table_ops *ops;
139 /** Opaque param to be passed to the table create operation */
143 /** IPv4 5-tuple data */
144 struct rte_flow_classify_ipv4_5tuple {
145 uint32_t dst_ip; /**< Destination IP address in big endian. */
146 uint32_t dst_ip_mask; /**< Mask of destination IP address. */
147 uint32_t src_ip; /**< Source IP address in big endian. */
148 uint32_t src_ip_mask; /**< Mask of destination IP address. */
149 uint16_t dst_port; /**< Destination port in big endian. */
150 uint16_t dst_port_mask; /**< Mask of destination port. */
151 uint16_t src_port; /**< Source Port in big endian. */
152 uint16_t src_port_mask; /**< Mask of source port. */
153 uint8_t proto; /**< L4 protocol. */
154 uint8_t proto_mask; /**< Mask of L4 protocol. */
160 * For the count action, stats can be returned by the query API.
162 * Storage for stats is provided by application.
164 struct rte_flow_classify_stats {
168 struct rte_flow_classify_ipv4_5tuple_stats {
169 /** count of packets that match IPv4 5tuple pattern */
171 /** IPv4 5tuple data */
172 struct rte_flow_classify_ipv4_5tuple ipv4_5tuple;
176 * Flow classifier create
179 * Parameters for flow classifier creation
181 * Handle to flow classifier instance on success or NULL otherwise
183 struct rte_flow_classifier *
184 rte_flow_classifier_create(struct rte_flow_classifier_params *params);
187 * Flow classifier free
190 * Handle to flow classifier instance
192 * 0 on success, error code otherwise
195 rte_flow_classifier_free(struct rte_flow_classifier *cls);
198 * Flow classify table create
201 * Handle to flow classifier instance
203 * Parameters for flow_classify table creation
205 * Table ID. Valid only within the scope of table IDs of the current
206 * classifier. Only returned after a successful invocation.
208 * 0 on success, error code otherwise
211 rte_flow_classify_table_create(struct rte_flow_classifier *cls,
212 struct rte_flow_classify_table_params *params,
216 * Add a flow classify rule to the flow_classifer table.
219 * Flow classifier handle
220 * @param[in] table_id
222 * @param[out] key_found
223 * returns 1 if key present already, 0 otherwise.
225 * Flow rule attributes
227 * Pattern specification (list terminated by the END pattern item).
229 * Associated actions (list terminated by the END pattern item).
231 * Perform verbose error reporting if not NULL. Structure
232 * initialised in case of error only.
234 * A valid handle in case of success, NULL otherwise.
236 struct rte_flow_classify_rule *
237 rte_flow_classify_table_entry_add(struct rte_flow_classifier *cls,
240 const struct rte_flow_attr *attr,
241 const struct rte_flow_item pattern[],
242 const struct rte_flow_action actions[],
243 struct rte_flow_error *error);
246 * Delete a flow classify rule from the flow_classifer table.
249 * Flow classifier handle
250 * @param[in] table_id
255 * 0 on success, error code otherwise.
258 rte_flow_classify_table_entry_delete(struct rte_flow_classifier *cls,
260 struct rte_flow_classify_rule *rule);
263 * Query flow classifier for given rule.
266 * Flow classifier handle
267 * @param[in] table_id
270 * Pointer to packets to process
272 * Number of packets to process
276 * Flow classify stats
279 * 0 on success, error code otherwise.
282 rte_flow_classifier_query(struct rte_flow_classifier *cls,
284 struct rte_mbuf **pkts,
285 const uint16_t nb_pkts,
286 struct rte_flow_classify_rule *rule,
287 struct rte_flow_classify_stats *stats);
293 #endif /* _RTE_FLOW_CLASSIFY_H_ */