examples/ip_pipeline: add TTL stats command
[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_mtr_params mtr;
264         struct rte_table_action_tm_params tm;
265         struct rte_table_action_encap_params encap;
266         struct rte_table_action_nat_params nat;
267         struct rte_table_action_ttl_params ttl;
268         struct rte_table_action_stats_params stats;
269         struct rte_table_action_time_params time;
270 };
271
272 int
273 pipeline_port_in_stats_read(const char *pipeline_name,
274         uint32_t port_id,
275         struct rte_pipeline_port_in_stats *stats,
276         int clear);
277
278 int
279 pipeline_port_in_enable(const char *pipeline_name,
280         uint32_t port_id);
281
282 int
283 pipeline_port_in_disable(const char *pipeline_name,
284         uint32_t port_id);
285
286 int
287 pipeline_port_out_stats_read(const char *pipeline_name,
288         uint32_t port_id,
289         struct rte_pipeline_port_out_stats *stats,
290         int clear);
291
292 int
293 pipeline_table_stats_read(const char *pipeline_name,
294         uint32_t table_id,
295         struct rte_pipeline_table_stats *stats,
296         int clear);
297
298 int
299 pipeline_table_rule_add(const char *pipeline_name,
300         uint32_t table_id,
301         struct table_rule_match *match,
302         struct table_rule_action *action,
303         void **data);
304
305 int
306 pipeline_table_rule_add_bulk(const char *pipeline_name,
307         uint32_t table_id,
308         struct table_rule_match *match,
309         struct table_rule_action *action,
310         void **data,
311         uint32_t *n_rules);
312
313 int
314 pipeline_table_rule_add_default(const char *pipeline_name,
315         uint32_t table_id,
316         struct table_rule_action *action,
317         void **data);
318
319 int
320 pipeline_table_rule_delete(const char *pipeline_name,
321         uint32_t table_id,
322         struct table_rule_match *match);
323
324 int
325 pipeline_table_rule_delete_default(const char *pipeline_name,
326         uint32_t table_id);
327
328 int
329 pipeline_table_rule_stats_read(const char *pipeline_name,
330         uint32_t table_id,
331         void *data,
332         struct rte_table_action_stats_counters *stats,
333         int clear);
334
335 int
336 pipeline_table_mtr_profile_add(const char *pipeline_name,
337         uint32_t table_id,
338         uint32_t meter_profile_id,
339         struct rte_table_action_meter_profile *profile);
340
341 int
342 pipeline_table_mtr_profile_delete(const char *pipeline_name,
343         uint32_t table_id,
344         uint32_t meter_profile_id);
345
346 int
347 pipeline_table_rule_mtr_read(const char *pipeline_name,
348         uint32_t table_id,
349         void *data,
350         uint32_t tc_mask,
351         struct rte_table_action_mtr_counters *stats,
352         int clear);
353
354 int
355 pipeline_table_dscp_table_update(const char *pipeline_name,
356         uint32_t table_id,
357         uint64_t dscp_mask,
358         struct rte_table_action_dscp_table *dscp_table);
359
360 int
361 pipeline_table_rule_ttl_read(const char *pipeline_name,
362         uint32_t table_id,
363         void *data,
364         struct rte_table_action_ttl_counters *stats,
365         int clear);
366
367 #endif /* _INCLUDE_PIPELINE_H_ */