xref: /dpdk/lib/pipeline/rte_swx_pipeline_spec.h (revision 770ebc060eb56731ae6ea0769ae10fda8eec5e89)
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  *	instanceof TABLE_TYPE_NAME
92  *	pragma ARGS
93  *	size SIZE
94  * }
95  */
96 struct table_spec {
97 	char *name;
98 	struct rte_swx_pipeline_table_params params;
99 	char *recommended_table_type_name;
100 	char *args;
101 	uint32_t size;
102 };
103 
104 /*
105  * selector.
106  *
107  * selector SELECTOR_NAME {
108  *	group_id FIELD_NAME
109  *	selector {
110  *		FIELD_NAME
111  *		...
112  *	}
113  *	member_id FIELD_NAME
114  *	n_groups N_GROUPS
115  *	n_members_per_group N_MEMBERS_PER_GROUP
116  * }
117  */
118 struct selector_spec {
119 	char *name;
120 	struct rte_swx_pipeline_selector_params params;
121 };
122 
123 /*
124  * learner.
125  *
126  * learner LEARNER_NAME {
127  *	key {
128  *		MATCH_FIELD_NAME
129  *		...
130  *	}
131  *	actions {
132  *		ACTION_NAME [ @tableonly | @defaultonly]
133  *		...
134  *	}
135  *	default_action ACTION_NAME args none | ARG0_NAME ARG0_VALUE ... [ const ]
136  *	size SIZE
137  *	timeout {
138  *		TIMEOUT_IN_SECONDS
139  *		...
140  *	}
141  * }
142  */
143 struct learner_spec {
144 	char *name;
145 	struct rte_swx_pipeline_learner_params params;
146 	uint32_t size;
147 	uint32_t *timeout;
148 	uint32_t n_timeouts;
149 };
150 
151 /*
152  * regarray.
153  *
154  * regarray NAME size SIZE initval INITVAL
155  */
156 struct regarray_spec {
157 	char *name;
158 	uint64_t init_val;
159 	uint32_t size;
160 };
161 
162 /*
163  * metarray.
164  *
165  * metarray NAME size SIZE
166  */
167 struct metarray_spec {
168 	char *name;
169 	uint32_t size;
170 };
171 
172 /*
173  * apply.
174  *
175  * apply {
176  *	INSTRUCTION
177  *	...
178  * }
179  */
180 struct apply_spec {
181 	const char **instructions;
182 	uint32_t n_instructions;
183 };
184 
185 /*
186  * Pipeline.
187  */
188 struct pipeline_spec {
189 	struct extobj_spec *extobjs;
190 	struct struct_spec *structs;
191 	struct header_spec *headers;
192 	struct metadata_spec *metadata;
193 	struct action_spec *actions;
194 	struct table_spec *tables;
195 	struct selector_spec *selectors;
196 	struct learner_spec *learners;
197 	struct regarray_spec *regarrays;
198 	struct metarray_spec *metarrays;
199 	struct apply_spec *apply;
200 
201 	uint32_t n_extobjs;
202 	uint32_t n_structs;
203 	uint32_t n_headers;
204 	uint32_t n_metadata;
205 	uint32_t n_actions;
206 	uint32_t n_tables;
207 	uint32_t n_selectors;
208 	uint32_t n_learners;
209 	uint32_t n_regarrays;
210 	uint32_t n_metarrays;
211 	uint32_t n_apply;
212 };
213 
214 /*
215  * Mirroring:
216  *      mirroring slots <n_slots> sessions <n_sessions>
217  *
218  * Input ports:
219  *      port in <port_id> ethdev <ethdev_name> rxq <queue_id> bsz <burst_size>
220  *      port in <port_id> ring <ring_name> bsz <burst_size>
221  *      port in <port_id> source mempool <mempool_name> file <file_name> loop <n_loops>
222  *                               packets <n_pkts_max>
223  *      port in <port_id> fd <file_descriptor> mtu <mtu> mempool <mempool_name> bsz <burst_size>
224  *
225  * Output ports:
226  *      port out <port_id> ethdev <ethdev_name> txq <queue_id> bsz <burst_size>
227  *      port out <port_id> ring <ring_name> bsz <burst_size>
228  *      port out <port_id> sink file <file_name> | none
229  *      port out <port_id> fd <file_descriptor> bsz <burst_size>
230  */
231 struct pipeline_iospec {
232 	struct rte_swx_pipeline_mirroring_params mirroring_params;
233 
234 	uint32_t *port_in_id;
235 	const char **port_in_type;
236 	void **port_in_params;
237 
238 	uint32_t *port_out_id;
239 	const char **port_out_type;
240 	void **port_out_params;
241 
242 	uint32_t n_ports_in;
243 	uint32_t n_ports_out;
244 };
245 
246 void
247 pipeline_spec_free(struct pipeline_spec *s);
248 
249 void
250 pipeline_spec_codegen(FILE *f,
251 		      struct pipeline_spec *s);
252 
253 struct pipeline_spec *
254 pipeline_spec_parse(FILE *spec,
255 		    uint32_t *err_line,
256 		    const char **err_msg);
257 
258 int
259 pipeline_spec_configure(struct rte_swx_pipeline *p,
260 			struct pipeline_spec *s,
261 			const char **err_msg);
262 
263 void
264 pipeline_iospec_free(struct pipeline_iospec *s);
265 
266 struct pipeline_iospec *
267 pipeline_iospec_parse(FILE *spec,
268 		      uint32_t *err_line,
269 		      const char **err_msg);
270 
271 int
272 pipeline_iospec_configure(struct rte_swx_pipeline *p,
273 			  struct pipeline_iospec *s,
274 			  const char **err_msg);
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif
281