8a364a923de8fee9267e1e9c7bc0cde580f5b80c
[dpdk.git] / examples / ip_pipeline / pipeline.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _INCLUDE_PIPELINE_H_
6 #define _INCLUDE_PIPELINE_H_
7
8 #include <stdint.h>
9 #include <sys/queue.h>
10
11 #include <rte_pipeline.h>
12 #include <rte_table_action.h>
13
14 #include "common.h"
15 #include "action.h"
16
17 struct pipeline_params {
18         uint32_t timer_period_ms;
19         uint32_t offset_port_id;
20         uint32_t cpu_id;
21 };
22
23 enum port_in_type {
24         PORT_IN_RXQ,
25         PORT_IN_SWQ,
26         PORT_IN_TMGR,
27         PORT_IN_TAP,
28         PORT_IN_KNI,
29         PORT_IN_SOURCE,
30         PORT_IN_CRYPTODEV,
31 };
32
33 struct port_in_params {
34         /* Read */
35         enum port_in_type type;
36         const char *dev_name;
37         union {
38                 struct {
39                         uint16_t queue_id;
40                 } rxq;
41
42                 struct {
43                         const char *mempool_name;
44                         uint32_t mtu;
45                 } tap;
46
47                 struct {
48                         const char *mempool_name;
49                         const char *file_name;
50                         uint32_t n_bytes_per_pkt;
51                 } source;
52
53                 struct {
54                         uint16_t queue_id;
55                         void *f_callback;
56                         void *arg_callback;
57                 } cryptodev;
58         };
59         uint32_t burst_size;
60
61         /* Action */
62         const char *action_profile_name;
63 };
64
65 enum port_out_type {
66         PORT_OUT_TXQ,
67         PORT_OUT_SWQ,
68         PORT_OUT_TMGR,
69         PORT_OUT_TAP,
70         PORT_OUT_KNI,
71         PORT_OUT_SINK,
72         PORT_OUT_CRYPTODEV,
73 };
74
75 struct port_out_params {
76         enum port_out_type type;
77         const char *dev_name;
78         union {
79                 struct {
80                         uint16_t queue_id;
81                 } txq;
82
83                 struct {
84                         const char *file_name;
85                         uint32_t max_n_pkts;
86                 } sink;
87
88                 struct {
89                         uint16_t queue_id;
90                         uint32_t op_offset;
91                 } cryptodev;
92         };
93         uint32_t burst_size;
94         int retry;
95         uint32_t n_retries;
96 };
97
98 enum table_type {
99         TABLE_ACL,
100         TABLE_ARRAY,
101         TABLE_HASH,
102         TABLE_LPM,
103         TABLE_STUB,
104 };
105
106 struct table_acl_params {
107         uint32_t n_rules;
108         uint32_t ip_header_offset;
109         int ip_version;
110 };
111
112 struct table_array_params {
113         uint32_t n_keys;
114         uint32_t key_offset;
115 };
116
117 struct table_hash_params {
118         uint32_t n_keys;
119         uint32_t key_offset;
120         uint32_t key_size;
121         uint8_t *key_mask;
122         uint32_t n_buckets;
123         int extendable_bucket;
124 };
125
126 struct table_lpm_params {
127         uint32_t n_rules;
128         uint32_t key_offset;
129         uint32_t key_size;
130 };
131
132 struct table_params {
133         /* Match */
134         enum table_type match_type;
135         union {
136                 struct table_acl_params acl;
137                 struct table_array_params array;
138                 struct table_hash_params hash;
139                 struct table_lpm_params lpm;
140         } match;
141
142         /* Action */
143         const char *action_profile_name;
144 };
145
146 struct table_rule;
147
148 TAILQ_HEAD(table_rule_list, table_rule);
149
150 struct port_in {
151         struct port_in_params params;
152         struct port_in_action_profile *ap;
153         struct rte_port_in_action *a;
154 };
155
156 struct table {
157         struct table_params params;
158         struct table_action_profile *ap;
159         struct rte_table_action *a;
160         struct table_rule_list rules;
161         struct table_rule *rule_default;
162 };
163
164 struct pipeline {
165         TAILQ_ENTRY(pipeline) node;
166         char name[NAME_SIZE];
167
168         struct rte_pipeline *p;
169         struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
170         struct table table[RTE_PIPELINE_TABLE_MAX];
171         uint32_t n_ports_in;
172         uint32_t n_ports_out;
173         uint32_t n_tables;
174
175         struct rte_ring *msgq_req;
176         struct rte_ring *msgq_rsp;
177         uint32_t timer_period_ms;
178
179         int enabled;
180         uint32_t thread_id;
181         uint32_t cpu_id;
182 };
183
184 TAILQ_HEAD(pipeline_list, pipeline);
185
186 int
187 pipeline_init(void);
188
189 struct pipeline *
190 pipeline_find(const char *name);
191
192 struct pipeline *
193 pipeline_create(const char *name, struct pipeline_params *params);
194
195 int
196 pipeline_port_in_create(const char *pipeline_name,
197         struct port_in_params *params,
198         int enabled);
199
200 int
201 pipeline_port_in_connect_to_table(const char *pipeline_name,
202         uint32_t port_id,
203         uint32_t table_id);
204
205 int
206 pipeline_port_out_create(const char *pipeline_name,
207         struct port_out_params *params);
208
209 int
210 pipeline_table_create(const char *pipeline_name,
211         struct table_params *params);
212
213 struct table_rule_match_acl {
214         int ip_version;
215
216         RTE_STD_C11
217         union {
218                 struct {
219                         uint32_t sa;
220                         uint32_t da;
221                 } ipv4;
222
223                 struct {
224                         uint8_t sa[16];
225                         uint8_t da[16];
226                 } ipv6;
227         };
228
229         uint32_t sa_depth;
230         uint32_t da_depth;
231         uint16_t sp0;
232         uint16_t sp1;
233         uint16_t dp0;
234         uint16_t dp1;
235         uint8_t proto;
236         uint8_t proto_mask;
237         uint32_t priority;
238 };
239
240 struct table_rule_match_array {
241         uint32_t pos;
242 };
243
244 #ifndef TABLE_RULE_MATCH_SIZE_MAX
245 #define TABLE_RULE_MATCH_SIZE_MAX                          256
246 #endif
247
248 #ifndef TABLE_RULE_ACTION_SIZE_MAX
249 #define TABLE_RULE_ACTION_SIZE_MAX                         2048
250 #endif
251
252 struct table_rule_match_hash {
253         uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
254 };
255
256 struct table_rule_match_lpm {
257         int ip_version;
258
259         RTE_STD_C11
260         union {
261                 uint32_t ipv4;
262                 uint8_t ipv6[16];
263         };
264
265         uint8_t depth;
266 };
267
268 struct table_rule_match {
269         enum table_type match_type;
270
271         union {
272                 struct table_rule_match_acl acl;
273                 struct table_rule_match_array array;
274                 struct table_rule_match_hash hash;
275                 struct table_rule_match_lpm lpm;
276         } match;
277 };
278
279 struct table_rule_action {
280         uint64_t action_mask;
281         struct rte_table_action_fwd_params fwd;
282         struct rte_table_action_lb_params lb;
283         struct rte_table_action_mtr_params mtr;
284         struct rte_table_action_tm_params tm;
285         struct rte_table_action_encap_params encap;
286         struct rte_table_action_nat_params nat;
287         struct rte_table_action_ttl_params ttl;
288         struct rte_table_action_stats_params stats;
289         struct rte_table_action_time_params time;
290         struct rte_table_action_sym_crypto_params sym_crypto;
291         struct rte_table_action_tag_params tag;
292         struct rte_table_action_decap_params decap;
293 };
294
295 struct table_rule {
296         TAILQ_ENTRY(table_rule) node;
297         struct table_rule_match match;
298         struct table_rule_action action;
299         void *data;
300 };
301
302 int
303 pipeline_port_in_stats_read(const char *pipeline_name,
304         uint32_t port_id,
305         struct rte_pipeline_port_in_stats *stats,
306         int clear);
307
308 int
309 pipeline_port_in_enable(const char *pipeline_name,
310         uint32_t port_id);
311
312 int
313 pipeline_port_in_disable(const char *pipeline_name,
314         uint32_t port_id);
315
316 int
317 pipeline_port_out_stats_read(const char *pipeline_name,
318         uint32_t port_id,
319         struct rte_pipeline_port_out_stats *stats,
320         int clear);
321
322 int
323 pipeline_table_stats_read(const char *pipeline_name,
324         uint32_t table_id,
325         struct rte_pipeline_table_stats *stats,
326         int clear);
327
328 int
329 pipeline_table_rule_add(const char *pipeline_name,
330         uint32_t table_id,
331         struct table_rule_match *match,
332         struct table_rule_action *action);
333
334 int
335 pipeline_table_rule_add_bulk(const char *pipeline_name,
336         uint32_t table_id,
337         struct table_rule_list *list,
338         uint32_t *n_rules_added,
339         uint32_t *n_rules_not_added);
340
341 int
342 pipeline_table_rule_add_default(const char *pipeline_name,
343         uint32_t table_id,
344         struct table_rule_action *action,
345         void **data);
346
347 int
348 pipeline_table_rule_delete(const char *pipeline_name,
349         uint32_t table_id,
350         struct table_rule_match *match);
351
352 int
353 pipeline_table_rule_delete_default(const char *pipeline_name,
354         uint32_t table_id);
355
356 int
357 pipeline_table_rule_stats_read(const char *pipeline_name,
358         uint32_t table_id,
359         void *data,
360         struct rte_table_action_stats_counters *stats,
361         int clear);
362
363 int
364 pipeline_table_mtr_profile_add(const char *pipeline_name,
365         uint32_t table_id,
366         uint32_t meter_profile_id,
367         struct rte_table_action_meter_profile *profile);
368
369 int
370 pipeline_table_mtr_profile_delete(const char *pipeline_name,
371         uint32_t table_id,
372         uint32_t meter_profile_id);
373
374 int
375 pipeline_table_rule_mtr_read(const char *pipeline_name,
376         uint32_t table_id,
377         void *data,
378         uint32_t tc_mask,
379         struct rte_table_action_mtr_counters *stats,
380         int clear);
381
382 int
383 pipeline_table_dscp_table_update(const char *pipeline_name,
384         uint32_t table_id,
385         uint64_t dscp_mask,
386         struct rte_table_action_dscp_table *dscp_table);
387
388 int
389 pipeline_table_rule_ttl_read(const char *pipeline_name,
390         uint32_t table_id,
391         void *data,
392         struct rte_table_action_ttl_counters *stats,
393         int clear);
394 struct table_rule *
395 table_rule_find(struct table *table,
396         struct table_rule_match *match);
397
398 void
399 table_rule_add(struct table *table,
400         struct table_rule *rule);
401
402 void
403 table_rule_add_bulk(struct table *table,
404         struct table_rule_list *list,
405         uint32_t n_rules);
406
407 void
408 table_rule_delete(struct table *table,
409         struct table_rule_match *match);
410
411 void
412 table_rule_default_add(struct table *table,
413         struct table_rule *rule);
414
415 void
416 table_rule_default_delete(struct table *table);
417
418 #endif /* _INCLUDE_PIPELINE_H_ */