xref: /dpdk/examples/ip_pipeline/pipeline.h (revision 6e9270eab112d68999a9124866dbfc46cd498d1b)
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 port_in {
147 	struct port_in_params params;
148 	struct port_in_action_profile *ap;
149 	struct rte_port_in_action *a;
150 };
151 
152 struct table {
153 	struct table_params params;
154 	struct table_action_profile *ap;
155 	struct rte_table_action *a;
156 };
157 
158 struct pipeline {
159 	TAILQ_ENTRY(pipeline) node;
160 	char name[NAME_SIZE];
161 
162 	struct rte_pipeline *p;
163 	struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
164 	struct table table[RTE_PIPELINE_TABLE_MAX];
165 	uint32_t n_ports_in;
166 	uint32_t n_ports_out;
167 	uint32_t n_tables;
168 
169 	struct rte_ring *msgq_req;
170 	struct rte_ring *msgq_rsp;
171 	uint32_t timer_period_ms;
172 
173 	int enabled;
174 	uint32_t thread_id;
175 	uint32_t cpu_id;
176 };
177 
178 TAILQ_HEAD(pipeline_list, pipeline);
179 
180 int
181 pipeline_init(void);
182 
183 struct pipeline *
184 pipeline_find(const char *name);
185 
186 struct pipeline *
187 pipeline_create(const char *name, struct pipeline_params *params);
188 
189 int
190 pipeline_port_in_create(const char *pipeline_name,
191 	struct port_in_params *params,
192 	int enabled);
193 
194 int
195 pipeline_port_in_connect_to_table(const char *pipeline_name,
196 	uint32_t port_id,
197 	uint32_t table_id);
198 
199 int
200 pipeline_port_out_create(const char *pipeline_name,
201 	struct port_out_params *params);
202 
203 int
204 pipeline_table_create(const char *pipeline_name,
205 	struct table_params *params);
206 
207 struct table_rule_match_acl {
208 	int ip_version;
209 
210 	RTE_STD_C11
211 	union {
212 		struct {
213 			uint32_t sa;
214 			uint32_t da;
215 		} ipv4;
216 
217 		struct {
218 			uint8_t sa[16];
219 			uint8_t da[16];
220 		} ipv6;
221 	};
222 
223 	uint32_t sa_depth;
224 	uint32_t da_depth;
225 	uint16_t sp0;
226 	uint16_t sp1;
227 	uint16_t dp0;
228 	uint16_t dp1;
229 	uint8_t proto;
230 	uint8_t proto_mask;
231 	uint32_t priority;
232 };
233 
234 struct table_rule_match_array {
235 	uint32_t pos;
236 };
237 
238 #ifndef TABLE_RULE_MATCH_SIZE_MAX
239 #define TABLE_RULE_MATCH_SIZE_MAX                          256
240 #endif
241 
242 #ifndef TABLE_RULE_ACTION_SIZE_MAX
243 #define TABLE_RULE_ACTION_SIZE_MAX                         2048
244 #endif
245 
246 struct table_rule_match_hash {
247 	uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
248 };
249 
250 struct table_rule_match_lpm {
251 	int ip_version;
252 
253 	RTE_STD_C11
254 	union {
255 		uint32_t ipv4;
256 		uint8_t ipv6[16];
257 	};
258 
259 	uint8_t depth;
260 };
261 
262 struct table_rule_match {
263 	enum table_type match_type;
264 
265 	union {
266 		struct table_rule_match_acl acl;
267 		struct table_rule_match_array array;
268 		struct table_rule_match_hash hash;
269 		struct table_rule_match_lpm lpm;
270 	} match;
271 };
272 
273 struct table_rule_action {
274 	uint64_t action_mask;
275 	struct rte_table_action_fwd_params fwd;
276 	struct rte_table_action_lb_params lb;
277 	struct rte_table_action_mtr_params mtr;
278 	struct rte_table_action_tm_params tm;
279 	struct rte_table_action_encap_params encap;
280 	struct rte_table_action_nat_params nat;
281 	struct rte_table_action_ttl_params ttl;
282 	struct rte_table_action_stats_params stats;
283 	struct rte_table_action_time_params time;
284 	struct rte_table_action_sym_crypto_params sym_crypto;
285 	struct rte_table_action_tag_params tag;
286 	struct rte_table_action_decap_params decap;
287 };
288 
289 int
290 pipeline_port_in_stats_read(const char *pipeline_name,
291 	uint32_t port_id,
292 	struct rte_pipeline_port_in_stats *stats,
293 	int clear);
294 
295 int
296 pipeline_port_in_enable(const char *pipeline_name,
297 	uint32_t port_id);
298 
299 int
300 pipeline_port_in_disable(const char *pipeline_name,
301 	uint32_t port_id);
302 
303 int
304 pipeline_port_out_stats_read(const char *pipeline_name,
305 	uint32_t port_id,
306 	struct rte_pipeline_port_out_stats *stats,
307 	int clear);
308 
309 int
310 pipeline_table_stats_read(const char *pipeline_name,
311 	uint32_t table_id,
312 	struct rte_pipeline_table_stats *stats,
313 	int clear);
314 
315 int
316 pipeline_table_rule_add(const char *pipeline_name,
317 	uint32_t table_id,
318 	struct table_rule_match *match,
319 	struct table_rule_action *action,
320 	void **data);
321 
322 int
323 pipeline_table_rule_add_bulk(const char *pipeline_name,
324 	uint32_t table_id,
325 	struct table_rule_match *match,
326 	struct table_rule_action *action,
327 	void **data,
328 	uint32_t *n_rules);
329 
330 int
331 pipeline_table_rule_add_default(const char *pipeline_name,
332 	uint32_t table_id,
333 	struct table_rule_action *action,
334 	void **data);
335 
336 int
337 pipeline_table_rule_delete(const char *pipeline_name,
338 	uint32_t table_id,
339 	struct table_rule_match *match);
340 
341 int
342 pipeline_table_rule_delete_default(const char *pipeline_name,
343 	uint32_t table_id);
344 
345 int
346 pipeline_table_rule_stats_read(const char *pipeline_name,
347 	uint32_t table_id,
348 	void *data,
349 	struct rte_table_action_stats_counters *stats,
350 	int clear);
351 
352 int
353 pipeline_table_mtr_profile_add(const char *pipeline_name,
354 	uint32_t table_id,
355 	uint32_t meter_profile_id,
356 	struct rte_table_action_meter_profile *profile);
357 
358 int
359 pipeline_table_mtr_profile_delete(const char *pipeline_name,
360 	uint32_t table_id,
361 	uint32_t meter_profile_id);
362 
363 int
364 pipeline_table_rule_mtr_read(const char *pipeline_name,
365 	uint32_t table_id,
366 	void *data,
367 	uint32_t tc_mask,
368 	struct rte_table_action_mtr_counters *stats,
369 	int clear);
370 
371 int
372 pipeline_table_dscp_table_update(const char *pipeline_name,
373 	uint32_t table_id,
374 	uint64_t dscp_mask,
375 	struct rte_table_action_dscp_table *dscp_table);
376 
377 int
378 pipeline_table_rule_ttl_read(const char *pipeline_name,
379 	uint32_t table_id,
380 	void *data,
381 	struct rte_table_action_ttl_counters *stats,
382 	int clear);
383 
384 #endif /* _INCLUDE_PIPELINE_H_ */
385