xref: /dpdk/lib/pipeline/rte_swx_pipeline_spec.h (revision 09442498ef736d0a96632cf8b8c15d8ca78a6468)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Intel Corporation
3  */
4 #ifndef __INCLUDE_RTE_SWX_PIPELINE_SPEC_H__
5 #define __INCLUDE_RTE_SWX_PIPELINE_SPEC_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include <stdint.h>
12 #include <stdio.h>
13 
14 #include <rte_common.h>
15 
16 #include <rte_swx_pipeline.h>
17 
18 /*
19  * extobj.
20  *
21  * extobj OBJ_NAME instanceof OBJ_TYPE [ pragma OBJ_CREATE_ARGS ]
22  */
23 struct extobj_spec {
24 	char *name;
25 	char *extern_type_name;
26 	char *pragma;
27 };
28 
29 /*
30  * struct.
31  *
32  * struct STRUCT_TYPE_NAME {
33  *	bit<SIZE> | varbit<SIZE> FIELD_NAME
34  *	...
35  * }
36  */
37 struct struct_spec {
38 	char *name;
39 	struct rte_swx_field_params *fields;
40 	uint32_t n_fields;
41 	int varbit;
42 };
43 
44 /*
45  * header.
46  *
47  * header HEADER_NAME instanceof STRUCT_TYPE_NAME
48  */
49 struct header_spec {
50 	char *name;
51 	char *struct_type_name;
52 };
53 
54 /*
55  * metadata.
56  *
57  * metadata instanceof STRUCT_TYPE_NAME
58  */
59 struct metadata_spec {
60 	char *struct_type_name;
61 };
62 
63 /*
64  * action.
65  *
66  * action ACTION_NAME args none | instanceof STRUCT_TYPE_NAME {
67  *	INSTRUCTION
68  *	...
69  * }
70  */
71 struct action_spec {
72 	char *name;
73 	char *args_struct_type_name;
74 	const char **instructions;
75 	uint32_t n_instructions;
76 };
77 
78 /*
79  * table.
80  *
81  * table TABLE_NAME {
82  *	key {
83  *		MATCH_FIELD_NAME exact | wildcard | lpm
84  *		...
85  *	}
86  *	actions {
87  *		ACTION_NAME [ @tableonly | @defaultonly ]
88  *		...
89  *	}
90  *	default_action ACTION_NAME args none | ARG0_NAME ARG0_VALUE ... [ const ]
91  *	hash HASH_FUNCTION_NAME
92  *	instanceof TABLE_TYPE_NAME
93  *	pragma ARGS
94  *	size SIZE
95  * }
96  */
97 struct table_spec {
98 	char *name;
99 	struct rte_swx_pipeline_table_params params;
100 	char *recommended_table_type_name;
101 	char *args;
102 	uint32_t size;
103 };
104 
105 /*
106  * selector.
107  *
108  * selector SELECTOR_NAME {
109  *	group_id FIELD_NAME
110  *	selector {
111  *		FIELD_NAME
112  *		...
113  *	}
114  *	member_id FIELD_NAME
115  *	n_groups N_GROUPS
116  *	n_members_per_group N_MEMBERS_PER_GROUP
117  * }
118  */
119 struct selector_spec {
120 	char *name;
121 	struct rte_swx_pipeline_selector_params params;
122 };
123 
124 /*
125  * learner.
126  *
127  * learner LEARNER_NAME {
128  *	key {
129  *		MATCH_FIELD_NAME
130  *		...
131  *	}
132  *	actions {
133  *		ACTION_NAME [ @tableonly | @defaultonly]
134  *		...
135  *	}
136  *	default_action ACTION_NAME args none | ARG0_NAME ARG0_VALUE ... [ const ]
137  *	hash HASH_FUNCTION_NAME
138  *	size SIZE
139  *	timeout {
140  *		TIMEOUT_IN_SECONDS
141  *		...
142  *	}
143  * }
144  */
145 struct learner_spec {
146 	char *name;
147 	struct rte_swx_pipeline_learner_params params;
148 	uint32_t size;
149 	uint32_t *timeout;
150 	uint32_t n_timeouts;
151 };
152 
153 /*
154  * regarray.
155  *
156  * regarray NAME size SIZE initval INITVAL
157  */
158 struct regarray_spec {
159 	char *name;
160 	uint64_t init_val;
161 	uint32_t size;
162 };
163 
164 /*
165  * metarray.
166  *
167  * metarray NAME size SIZE
168  */
169 struct metarray_spec {
170 	char *name;
171 	uint32_t size;
172 };
173 
174 /*
175  * apply.
176  *
177  * apply {
178  *	INSTRUCTION
179  *	...
180  * }
181  */
182 struct apply_spec {
183 	const char **instructions;
184 	uint32_t n_instructions;
185 };
186 
187 /*
188  * Pipeline.
189  */
190 struct pipeline_spec {
191 	struct extobj_spec *extobjs;
192 	struct struct_spec *structs;
193 	struct header_spec *headers;
194 	struct metadata_spec *metadata;
195 	struct action_spec *actions;
196 	struct table_spec *tables;
197 	struct selector_spec *selectors;
198 	struct learner_spec *learners;
199 	struct regarray_spec *regarrays;
200 	struct metarray_spec *metarrays;
201 	struct apply_spec *apply;
202 
203 	uint32_t n_extobjs;
204 	uint32_t n_structs;
205 	uint32_t n_headers;
206 	uint32_t n_metadata;
207 	uint32_t n_actions;
208 	uint32_t n_tables;
209 	uint32_t n_selectors;
210 	uint32_t n_learners;
211 	uint32_t n_regarrays;
212 	uint32_t n_metarrays;
213 	uint32_t n_apply;
214 };
215 
216 /*
217  * Mirroring:
218  *      mirroring slots <n_slots> sessions <n_sessions>
219  *
220  * Input ports:
221  *      port in <port_id> ethdev <ethdev_name> rxq <queue_id> bsz <burst_size>
222  *      port in <port_id> ring <ring_name> bsz <burst_size>
223  *      port in <port_id> source mempool <mempool_name> file <file_name> loop <n_loops>
224  *                               packets <n_pkts_max>
225  *      port in <port_id> fd <file_descriptor> mtu <mtu> mempool <mempool_name> bsz <burst_size>
226  *
227  * Output ports:
228  *      port out <port_id> ethdev <ethdev_name> txq <queue_id> bsz <burst_size>
229  *      port out <port_id> ring <ring_name> bsz <burst_size>
230  *      port out <port_id> sink file <file_name> | none
231  *      port out <port_id> fd <file_descriptor> bsz <burst_size>
232  */
233 struct pipeline_iospec {
234 	struct rte_swx_pipeline_mirroring_params mirroring_params;
235 
236 	uint32_t *port_in_id;
237 	const char **port_in_type;
238 	void **port_in_params;
239 
240 	uint32_t *port_out_id;
241 	const char **port_out_type;
242 	void **port_out_params;
243 
244 	uint32_t n_ports_in;
245 	uint32_t n_ports_out;
246 };
247 
248 void
249 pipeline_spec_free(struct pipeline_spec *s);
250 
251 void
252 pipeline_spec_codegen(FILE *f,
253 		      struct pipeline_spec *s);
254 
255 struct pipeline_spec *
256 pipeline_spec_parse(FILE *spec,
257 		    uint32_t *err_line,
258 		    const char **err_msg);
259 
260 int
261 pipeline_spec_configure(struct rte_swx_pipeline *p,
262 			struct pipeline_spec *s,
263 			const char **err_msg);
264 
265 void
266 pipeline_iospec_free(struct pipeline_iospec *s);
267 
268 struct pipeline_iospec *
269 pipeline_iospec_parse(FILE *spec,
270 		      uint32_t *err_line,
271 		      const char **err_msg);
272 
273 int
274 pipeline_iospec_configure(struct rte_swx_pipeline *p,
275 			  struct pipeline_iospec *s,
276 			  const char **err_msg);
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif
283