flow_classify: remove table id parameter from API
[dpdk.git] / lib / librte_flow_classify / rte_flow_classify.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _RTE_FLOW_CLASSIFY_H_
6 #define _RTE_FLOW_CLASSIFY_H_
7
8 /**
9  * @file
10  *
11  * RTE Flow Classify Library
12  *
13  * @b EXPERIMENTAL: this API may change without prior notice
14  *
15  * This library provides flow record information with some measured properties.
16  *
17  * Application should define the flow and measurement criteria (action) for it.
18  *
19  * The Library doesn't maintain any flow records itself, instead flow
20  * information is returned to upper layer only for given packets.
21  *
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
24  * them.
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.
29  *
30  *  Usage:
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()
42  */
43
44 #include <rte_ethdev.h>
45 #include <rte_ether.h>
46 #include <rte_flow.h>
47 #include <rte_acl.h>
48 #include <rte_table_acl.h>
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 extern int librte_flow_classify_logtype;
55
56 #define RTE_FLOW_CLASSIFY_LOG(level, fmt, args...) \
57 rte_log(RTE_LOG_ ## level, librte_flow_classify_logtype, "%s(): " fmt, \
58         __func__, ## args)
59
60 #ifndef RTE_FLOW_CLASSIFY_TABLE_MAX
61 #define RTE_FLOW_CLASSIFY_TABLE_MAX             32
62 #endif
63
64 /** Opaque data type for flow classifier */
65 struct rte_flow_classifier;
66
67 /** Opaque data type for flow classify rule */
68 struct rte_flow_classify_rule;
69
70 /** Flow classify rule type */
71 enum rte_flow_classify_rule_type {
72         /** no type */
73         RTE_FLOW_CLASSIFY_RULE_TYPE_NONE,
74         /** IPv4 5tuple type */
75         RTE_FLOW_CLASSIFY_RULE_TYPE_IPV4_5TUPLE,
76 };
77
78 /** Flow classify table type */
79 enum rte_flow_classify_table_type {
80         /** No type */
81         RTE_FLOW_CLASSIFY_TABLE_TYPE_NONE = 1 << 0,
82         /** ACL IP4 5TUPLE */
83         RTE_FLOW_CLASSIFY_TABLE_ACL_IP4_5TUPLE = 1 << 1,
84         /** ACL VLAN IP4 5TUPLE */
85         RTE_FLOW_CLASSIFY_TABLE_ACL_VLAN_IP4_5TUPLE = 1 << 2,
86         /** ACL QinQ IP4 5TUPLE */
87         RTE_FLOW_CLASSIFY_TABLE_ACL_QINQ_IP4_5TUPLE = 1 << 3,
88
89 };
90
91 /** Parameters for flow classifier creation */
92 struct rte_flow_classifier_params {
93         /** flow classifier name */
94         const char *name;
95
96         /** CPU socket ID where memory for the flow classifier and its */
97         /** elements (tables) should be allocated */
98         int socket_id;
99 };
100
101 /** Parameters for table creation */
102 struct rte_flow_classify_table_params {
103         /** Table operations (specific to each table type) */
104         struct rte_table_ops *ops;
105
106         /** Opaque param to be passed to the table create operation */
107         void *arg_create;
108
109         /** Classifier table type */
110         enum rte_flow_classify_table_type type;
111 };
112
113 /** IPv4 5-tuple data */
114 struct rte_flow_classify_ipv4_5tuple {
115         uint32_t dst_ip;         /**< Destination IP address in big endian. */
116         uint32_t dst_ip_mask;    /**< Mask of destination IP address. */
117         uint32_t src_ip;         /**< Source IP address in big endian. */
118         uint32_t src_ip_mask;    /**< Mask of destination IP address. */
119         uint16_t dst_port;       /**< Destination port in big endian. */
120         uint16_t dst_port_mask;  /**< Mask of destination port. */
121         uint16_t src_port;       /**< Source Port in big endian. */
122         uint16_t src_port_mask;  /**< Mask of source port. */
123         uint8_t proto;           /**< L4 protocol. */
124         uint8_t proto_mask;      /**< Mask of L4 protocol. */
125 };
126
127 /**
128  * Flow stats
129  *
130  * For the count action, stats can be returned by the query API.
131  *
132  * Storage for stats is provided by application.
133  */
134 struct rte_flow_classify_stats {
135         void *stats;
136 };
137
138 struct rte_flow_classify_ipv4_5tuple_stats {
139         /** count of packets that match IPv4 5tuple pattern */
140         uint64_t counter1;
141         /** IPv4 5tuple data */
142         struct rte_flow_classify_ipv4_5tuple ipv4_5tuple;
143 };
144
145 /**
146  * Flow classifier create
147  *
148  * @param params
149  *   Parameters for flow classifier creation
150  * @return
151  *   Handle to flow classifier instance on success or NULL otherwise
152  */
153 struct rte_flow_classifier *
154 rte_flow_classifier_create(struct rte_flow_classifier_params *params);
155
156 /**
157  * Flow classifier free
158  *
159  * @param cls
160  *   Handle to flow classifier instance
161  * @return
162  *   0 on success, error code otherwise
163  */
164 int
165 rte_flow_classifier_free(struct rte_flow_classifier *cls);
166
167 /**
168  * Flow classify table create
169  *
170  * @param cls
171  *   Handle to flow classifier instance
172  * @param params
173  *   Parameters for flow_classify table creation
174  * @return
175  *   0 on success, error code otherwise
176  */
177 int
178 rte_flow_classify_table_create(struct rte_flow_classifier *cls,
179                 struct rte_flow_classify_table_params *params);
180
181 /**
182  * Flow classify validate
183  *
184  * @param cls
185  *   Handle to flow classifier instance
186  * @param[in] attr
187  *   Flow rule attributes
188  * @param[in] pattern
189  *   Pattern specification (list terminated by the END pattern item).
190  * @param[in] actions
191  *   Associated actions (list terminated by the END pattern item).
192  * @param[out] error
193  *   Perform verbose error reporting if not NULL. Structure
194  *   initialised in case of error only.
195  * @return
196  *   0 on success, error code otherwise
197  */
198 int
199 rte_flow_classify_validate(struct rte_flow_classifier *cls,
200                 const struct rte_flow_attr *attr,
201                 const struct rte_flow_item pattern[],
202                 const struct rte_flow_action actions[],
203                 struct rte_flow_error *error);
204
205 /**
206  * Add a flow classify rule to the flow_classifer table.
207  *
208  * @param[in] cls
209  *   Flow classifier handle
210  * @param[in] attr
211  *   Flow rule attributes
212  * @param[in] pattern
213  *   Pattern specification (list terminated by the END pattern item).
214  * @param[in] actions
215  *   Associated actions (list terminated by the END pattern item).
216  * @param[out] key_found
217  *  returns 1 if rule present already, 0 otherwise.
218  * @param[out] error
219  *   Perform verbose error reporting if not NULL. Structure
220  *   initialised in case of error only.
221  * @return
222  *   A valid handle in case of success, NULL otherwise.
223  */
224 struct rte_flow_classify_rule *
225 rte_flow_classify_table_entry_add(struct rte_flow_classifier *cls,
226                 const struct rte_flow_attr *attr,
227                 const struct rte_flow_item pattern[],
228                 const struct rte_flow_action actions[],
229                 int *key_found,
230                 struct rte_flow_error *error);
231
232 /**
233  * Delete a flow classify rule from the flow_classifer table.
234  *
235  * @param[in] cls
236  *   Flow classifier handle
237  * @param[in] rule
238  *   Flow classify rule
239  * @return
240  *   0 on success, error code otherwise.
241  */
242 int
243 rte_flow_classify_table_entry_delete(struct rte_flow_classifier *cls,
244                 struct rte_flow_classify_rule *rule);
245
246 /**
247  * Query flow classifier for given rule.
248  *
249  * @param[in] cls
250  *   Flow classifier handle
251  * @param[in] pkts
252  *   Pointer to packets to process
253  * @param[in] nb_pkts
254  *   Number of packets to process
255  * @param[in] rule
256  *   Flow classify rule
257  * @param[in] stats
258  *   Flow classify stats
259  *
260  * @return
261  *   0 on success, error code otherwise.
262  */
263 int
264 rte_flow_classifier_query(struct rte_flow_classifier *cls,
265                 struct rte_mbuf **pkts,
266                 const uint16_t nb_pkts,
267                 struct rte_flow_classify_rule *rule,
268                 struct rte_flow_classify_stats *stats);
269
270 #ifdef __cplusplus
271 }
272 #endif
273
274 #endif /* _RTE_FLOW_CLASSIFY_H_ */