test mbuf attach
[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 #ifndef SYM_CRYPTO_MAX_KEY_SIZE
280 #define SYM_CRYPTO_MAX_KEY_SIZE                (256)
281 #endif
282
283 struct table_rule_action {
284         uint64_t action_mask;
285         struct rte_table_action_fwd_params fwd;
286         struct rte_table_action_lb_params lb;
287         struct rte_table_action_mtr_params mtr;
288         struct rte_table_action_tm_params tm;
289         struct rte_table_action_encap_params encap;
290         struct rte_table_action_nat_params nat;
291         struct rte_table_action_ttl_params ttl;
292         struct rte_table_action_stats_params stats;
293         struct rte_table_action_time_params time;
294         struct rte_table_action_sym_crypto_params sym_crypto;
295         uint8_t sym_crypto_key[SYM_CRYPTO_MAX_KEY_SIZE];
296         struct rte_table_action_tag_params tag;
297         struct rte_table_action_decap_params decap;
298
299 };
300
301 struct table_rule {
302         TAILQ_ENTRY(table_rule) node;
303         struct table_rule_match match;
304         struct table_rule_action action;
305         void *data;
306 };
307
308 int
309 pipeline_port_in_stats_read(const char *pipeline_name,
310         uint32_t port_id,
311         struct rte_pipeline_port_in_stats *stats,
312         int clear);
313
314 int
315 pipeline_port_in_enable(const char *pipeline_name,
316         uint32_t port_id);
317
318 int
319 pipeline_port_in_disable(const char *pipeline_name,
320         uint32_t port_id);
321
322 int
323 pipeline_port_out_stats_read(const char *pipeline_name,
324         uint32_t port_id,
325         struct rte_pipeline_port_out_stats *stats,
326         int clear);
327
328 int
329 pipeline_table_stats_read(const char *pipeline_name,
330         uint32_t table_id,
331         struct rte_pipeline_table_stats *stats,
332         int clear);
333
334 int
335 pipeline_table_rule_add(const char *pipeline_name,
336         uint32_t table_id,
337         struct table_rule_match *match,
338         struct table_rule_action *action);
339
340 int
341 pipeline_table_rule_add_bulk(const char *pipeline_name,
342         uint32_t table_id,
343         struct table_rule_list *list,
344         uint32_t *n_rules_added,
345         uint32_t *n_rules_not_added);
346
347 int
348 pipeline_table_rule_add_default(const char *pipeline_name,
349         uint32_t table_id,
350         struct table_rule_action *action);
351
352 int
353 pipeline_table_rule_delete(const char *pipeline_name,
354         uint32_t table_id,
355         struct table_rule_match *match);
356
357 int
358 pipeline_table_rule_delete_default(const char *pipeline_name,
359         uint32_t table_id);
360
361 int
362 pipeline_table_rule_stats_read(const char *pipeline_name,
363         uint32_t table_id,
364         struct table_rule_match *match,
365         struct rte_table_action_stats_counters *stats,
366         int clear);
367
368 int
369 pipeline_table_mtr_profile_add(const char *pipeline_name,
370         uint32_t table_id,
371         uint32_t meter_profile_id,
372         struct rte_table_action_meter_profile *profile);
373
374 int
375 pipeline_table_mtr_profile_delete(const char *pipeline_name,
376         uint32_t table_id,
377         uint32_t meter_profile_id);
378
379 int
380 pipeline_table_rule_mtr_read(const char *pipeline_name,
381         uint32_t table_id,
382         struct table_rule_match *match,
383         struct rte_table_action_mtr_counters *stats,
384         int clear);
385
386 int
387 pipeline_table_dscp_table_update(const char *pipeline_name,
388         uint32_t table_id,
389         uint64_t dscp_mask,
390         struct rte_table_action_dscp_table *dscp_table);
391
392 int
393 pipeline_table_rule_ttl_read(const char *pipeline_name,
394         uint32_t table_id,
395         struct table_rule_match *match,
396         struct rte_table_action_ttl_counters *stats,
397         int clear);
398
399 int
400 pipeline_table_rule_time_read(const char *pipeline_name,
401         uint32_t table_id,
402         struct table_rule_match *match,
403         uint64_t *timestamp);
404
405 struct table_rule *
406 table_rule_find(struct table *table,
407         struct table_rule_match *match);
408
409 void
410 table_rule_add(struct table *table,
411         struct table_rule *rule);
412
413 void
414 table_rule_add_bulk(struct table *table,
415         struct table_rule_list *list,
416         uint32_t n_rules);
417
418 void
419 table_rule_delete(struct table *table,
420         struct table_rule_match *match);
421
422 void
423 table_rule_default_add(struct table *table,
424         struct table_rule *rule);
425
426 void
427 table_rule_default_delete(struct table *table);
428
429 #endif /* _INCLUDE_PIPELINE_H_ */