fix ethdev port id validation
[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 };
31
32 struct port_in_params {
33         /* Read */
34         enum port_in_type type;
35         const char *dev_name;
36         union {
37                 struct {
38                         uint16_t queue_id;
39                 } rxq;
40
41                 struct {
42                         const char *mempool_name;
43                         uint32_t mtu;
44                 } tap;
45
46                 struct {
47                         const char *mempool_name;
48                         const char *file_name;
49                         uint32_t n_bytes_per_pkt;
50                 } source;
51         };
52         uint32_t burst_size;
53
54         /* Action */
55         const char *action_profile_name;
56 };
57
58 enum port_out_type {
59         PORT_OUT_TXQ,
60         PORT_OUT_SWQ,
61         PORT_OUT_TMGR,
62         PORT_OUT_TAP,
63         PORT_OUT_KNI,
64         PORT_OUT_SINK,
65 };
66
67 struct port_out_params {
68         enum port_out_type type;
69         const char *dev_name;
70         union {
71                 struct {
72                         uint16_t queue_id;
73                 } txq;
74
75                 struct {
76                         const char *file_name;
77                         uint32_t max_n_pkts;
78                 } sink;
79         };
80         uint32_t burst_size;
81         int retry;
82         uint32_t n_retries;
83 };
84
85 enum table_type {
86         TABLE_ACL,
87         TABLE_ARRAY,
88         TABLE_HASH,
89         TABLE_LPM,
90         TABLE_STUB,
91 };
92
93 struct table_acl_params {
94         uint32_t n_rules;
95         uint32_t ip_header_offset;
96         int ip_version;
97 };
98
99 struct table_array_params {
100         uint32_t n_keys;
101         uint32_t key_offset;
102 };
103
104 struct table_hash_params {
105         uint32_t n_keys;
106         uint32_t key_offset;
107         uint32_t key_size;
108         uint8_t *key_mask;
109         uint32_t n_buckets;
110         int extendable_bucket;
111 };
112
113 struct table_lpm_params {
114         uint32_t n_rules;
115         uint32_t key_offset;
116         uint32_t key_size;
117 };
118
119 struct table_params {
120         /* Match */
121         enum table_type match_type;
122         union {
123                 struct table_acl_params acl;
124                 struct table_array_params array;
125                 struct table_hash_params hash;
126                 struct table_lpm_params lpm;
127         } match;
128
129         /* Action */
130         const char *action_profile_name;
131 };
132
133 struct port_in {
134         struct port_in_params params;
135         struct port_in_action_profile *ap;
136         struct rte_port_in_action *a;
137 };
138
139 struct table {
140         struct table_params params;
141         struct table_action_profile *ap;
142         struct rte_table_action *a;
143 };
144
145 struct pipeline {
146         TAILQ_ENTRY(pipeline) node;
147         char name[NAME_SIZE];
148
149         struct rte_pipeline *p;
150         struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
151         struct table table[RTE_PIPELINE_TABLE_MAX];
152         uint32_t n_ports_in;
153         uint32_t n_ports_out;
154         uint32_t n_tables;
155
156         struct rte_ring *msgq_req;
157         struct rte_ring *msgq_rsp;
158         uint32_t timer_period_ms;
159
160         int enabled;
161         uint32_t thread_id;
162         uint32_t cpu_id;
163 };
164
165 TAILQ_HEAD(pipeline_list, pipeline);
166
167 int
168 pipeline_init(void);
169
170 struct pipeline *
171 pipeline_find(const char *name);
172
173 struct pipeline *
174 pipeline_create(const char *name, struct pipeline_params *params);
175
176 int
177 pipeline_port_in_create(const char *pipeline_name,
178         struct port_in_params *params,
179         int enabled);
180
181 int
182 pipeline_port_in_connect_to_table(const char *pipeline_name,
183         uint32_t port_id,
184         uint32_t table_id);
185
186 int
187 pipeline_port_out_create(const char *pipeline_name,
188         struct port_out_params *params);
189
190 int
191 pipeline_table_create(const char *pipeline_name,
192         struct table_params *params);
193
194 struct table_rule_match_acl {
195         int ip_version;
196
197         RTE_STD_C11
198         union {
199                 struct {
200                         uint32_t sa;
201                         uint32_t da;
202                 } ipv4;
203
204                 struct {
205                         uint8_t sa[16];
206                         uint8_t da[16];
207                 } ipv6;
208         };
209
210         uint32_t sa_depth;
211         uint32_t da_depth;
212         uint16_t sp0;
213         uint16_t sp1;
214         uint16_t dp0;
215         uint16_t dp1;
216         uint8_t proto;
217         uint8_t proto_mask;
218         uint32_t priority;
219 };
220
221 struct table_rule_match_array {
222         uint32_t pos;
223 };
224
225 #ifndef TABLE_RULE_MATCH_SIZE_MAX
226 #define TABLE_RULE_MATCH_SIZE_MAX                          256
227 #endif
228
229 #ifndef TABLE_RULE_ACTION_SIZE_MAX
230 #define TABLE_RULE_ACTION_SIZE_MAX                         2048
231 #endif
232
233 struct table_rule_match_hash {
234         uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
235 };
236
237 struct table_rule_match_lpm {
238         int ip_version;
239
240         RTE_STD_C11
241         union {
242                 uint32_t ipv4;
243                 uint8_t ipv6[16];
244         };
245
246         uint8_t depth;
247 };
248
249 struct table_rule_match {
250         enum table_type match_type;
251
252         union {
253                 struct table_rule_match_acl acl;
254                 struct table_rule_match_array array;
255                 struct table_rule_match_hash hash;
256                 struct table_rule_match_lpm lpm;
257         } match;
258 };
259
260 struct table_rule_action {
261         uint64_t action_mask;
262         struct rte_table_action_fwd_params fwd;
263         struct rte_table_action_lb_params lb;
264         struct rte_table_action_mtr_params mtr;
265         struct rte_table_action_tm_params tm;
266         struct rte_table_action_encap_params encap;
267         struct rte_table_action_nat_params nat;
268         struct rte_table_action_ttl_params ttl;
269         struct rte_table_action_stats_params stats;
270         struct rte_table_action_time_params time;
271 };
272
273 int
274 pipeline_port_in_stats_read(const char *pipeline_name,
275         uint32_t port_id,
276         struct rte_pipeline_port_in_stats *stats,
277         int clear);
278
279 int
280 pipeline_port_in_enable(const char *pipeline_name,
281         uint32_t port_id);
282
283 int
284 pipeline_port_in_disable(const char *pipeline_name,
285         uint32_t port_id);
286
287 int
288 pipeline_port_out_stats_read(const char *pipeline_name,
289         uint32_t port_id,
290         struct rte_pipeline_port_out_stats *stats,
291         int clear);
292
293 int
294 pipeline_table_stats_read(const char *pipeline_name,
295         uint32_t table_id,
296         struct rte_pipeline_table_stats *stats,
297         int clear);
298
299 int
300 pipeline_table_rule_add(const char *pipeline_name,
301         uint32_t table_id,
302         struct table_rule_match *match,
303         struct table_rule_action *action,
304         void **data);
305
306 int
307 pipeline_table_rule_add_bulk(const char *pipeline_name,
308         uint32_t table_id,
309         struct table_rule_match *match,
310         struct table_rule_action *action,
311         void **data,
312         uint32_t *n_rules);
313
314 int
315 pipeline_table_rule_add_default(const char *pipeline_name,
316         uint32_t table_id,
317         struct table_rule_action *action,
318         void **data);
319
320 int
321 pipeline_table_rule_delete(const char *pipeline_name,
322         uint32_t table_id,
323         struct table_rule_match *match);
324
325 int
326 pipeline_table_rule_delete_default(const char *pipeline_name,
327         uint32_t table_id);
328
329 int
330 pipeline_table_rule_stats_read(const char *pipeline_name,
331         uint32_t table_id,
332         void *data,
333         struct rte_table_action_stats_counters *stats,
334         int clear);
335
336 int
337 pipeline_table_mtr_profile_add(const char *pipeline_name,
338         uint32_t table_id,
339         uint32_t meter_profile_id,
340         struct rte_table_action_meter_profile *profile);
341
342 int
343 pipeline_table_mtr_profile_delete(const char *pipeline_name,
344         uint32_t table_id,
345         uint32_t meter_profile_id);
346
347 int
348 pipeline_table_rule_mtr_read(const char *pipeline_name,
349         uint32_t table_id,
350         void *data,
351         uint32_t tc_mask,
352         struct rte_table_action_mtr_counters *stats,
353         int clear);
354
355 int
356 pipeline_table_dscp_table_update(const char *pipeline_name,
357         uint32_t table_id,
358         uint64_t dscp_mask,
359         struct rte_table_action_dscp_table *dscp_table);
360
361 int
362 pipeline_table_rule_ttl_read(const char *pipeline_name,
363         uint32_t table_id,
364         void *data,
365         struct rte_table_action_ttl_counters *stats,
366         int clear);
367
368 #endif /* _INCLUDE_PIPELINE_H_ */