DPDK  24.03.0
rte_swx_pipeline_spec.h
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  * rss.
176  *
177  * rss NAME
178  */
179 struct rss_spec {
180  char *name;
181 };
182 
183 /*
184  * apply.
185  *
186  * apply {
187  * INSTRUCTION
188  * ...
189  * }
190  */
191 struct apply_spec {
192  const char **instructions;
193  uint32_t n_instructions;
194 };
195 
196 /*
197  * Pipeline.
198  */
199 struct pipeline_spec {
200  struct extobj_spec *extobjs;
201  struct struct_spec *structs;
202  struct header_spec *headers;
203  struct metadata_spec *metadata;
204  struct action_spec *actions;
205  struct table_spec *tables;
206  struct selector_spec *selectors;
207  struct learner_spec *learners;
208  struct regarray_spec *regarrays;
209  struct metarray_spec *metarrays;
210  struct rss_spec *rss;
211  struct apply_spec *apply;
212 
213  uint32_t n_extobjs;
214  uint32_t n_structs;
215  uint32_t n_headers;
216  uint32_t n_metadata;
217  uint32_t n_actions;
218  uint32_t n_tables;
219  uint32_t n_selectors;
220  uint32_t n_learners;
221  uint32_t n_regarrays;
222  uint32_t n_metarrays;
223  uint32_t n_rss;
224  uint32_t n_apply;
225 };
226 
227 /*
228  * Mirroring:
229  * mirroring slots <n_slots> sessions <n_sessions>
230  *
231  * Input ports:
232  * port in <port_id> ethdev <ethdev_name> rxq <queue_id> bsz <burst_size>
233  * port in <port_id> ring <ring_name> bsz <burst_size>
234  * port in <port_id> source mempool <mempool_name> file <file_name> loop <n_loops>
235  * packets <n_pkts_max>
236  * port in <port_id> fd <file_descriptor> mtu <mtu> mempool <mempool_name> bsz <burst_size>
237  *
238  * Output ports:
239  * port out <port_id> ethdev <ethdev_name> txq <queue_id> bsz <burst_size>
240  * port out <port_id> ring <ring_name> bsz <burst_size>
241  * port out <port_id> sink file <file_name> | none
242  * port out <port_id> fd <file_descriptor> bsz <burst_size>
243  */
244 struct pipeline_iospec {
245  struct rte_swx_pipeline_mirroring_params mirroring_params;
246 
247  uint32_t *port_in_id;
248  const char **port_in_type;
249  void **port_in_params;
250 
251  uint32_t *port_out_id;
252  const char **port_out_type;
253  void **port_out_params;
254 
255  uint32_t n_ports_in;
256  uint32_t n_ports_out;
257 };
258 
259 void
260 pipeline_spec_free(struct pipeline_spec *s);
261 
262 void
263 pipeline_spec_codegen(FILE *f,
264  struct pipeline_spec *s);
265 
266 struct pipeline_spec *
267 pipeline_spec_parse(FILE *spec,
268  uint32_t *err_line,
269  const char **err_msg);
270 
271 int
272 pipeline_spec_configure(struct rte_swx_pipeline *p,
273  struct pipeline_spec *s,
274  const char **err_msg);
275 
276 void
277 pipeline_iospec_free(struct pipeline_iospec *s);
278 
279 struct pipeline_iospec *
280 pipeline_iospec_parse(FILE *spec,
281  uint32_t *err_line,
282  const char **err_msg);
283 
284 int
285 pipeline_iospec_configure(struct rte_swx_pipeline *p,
286  struct pipeline_iospec *s,
287  const char **err_msg);
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif