forked from sonic-net/DASH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saiapi.h.j2
427 lines (394 loc) · 14.1 KB
/
saiapi.h.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/**
* Copyright (c) 2014 Microsoft Open Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
* LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
* FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
*
* See the Apache Version 2.0 License for specific language governing
* permissions and limitations under the License.
*
* Microsoft would like to thank the following companies for their review and
* assistance with these files: Intel Corporation, Mellanox Technologies Ltd,
* Dell Products, L.P., Facebook, Inc., Marvell International Ltd.
*
* @file saiexperimental{{ sai_api.app_name | replace('_', '') }}.h
*
* @brief This module defines SAI P4 extension interface
*/
#if !defined (__SAIEXPERIMENTAL{{ sai_api.app_name | replace('_', '') | upper }}_H_)
#define __SAIEXPERIMENTAL{{ sai_api.app_name | replace('_', '') | upper}}_H_
#include <saitypes.h>
/**
* @defgroup SAIEXPERIMENTAL{{ sai_api.app_name | upper}} SAI - Extension specific API definitions
*
* @{
*/
{% for table in sai_api.tables %}
{% if table.actions | length > 1 or ((table.actions | length == 1) and (((table.is_object == 'false') or (table['keys'] | length <= 1)) and ((table['actionParams'] | length == 0)))) %}
/**
* @brief Attribute data for #SAI_{{ table.name | upper }}_ATTR_ACTION
*/
typedef enum _sai_{{ table.name }}_action_t
{
{% for action in table.actions %}
SAI_{{ table.name | upper }}_ACTION_{{ action.name | upper }},
{% endfor %}
} sai_{{ table.name }}_action_t;
{% endif %}
{% endfor %}
{% for table in sai_api.tables %}
{% if table.is_object == 'false' %}
/**
* @brief Entry for {{ table.name }}
*/
typedef struct _sai_{{ table.name }}_t
{
/**
* @brief Switch ID
*
* @objects SAI_OBJECT_TYPE_SWITCH
*/
sai_object_id_t switch_id;
{% for key in table['keys'] %}
/**
* @brief {{ key.match_type | capitalize | replace('Lpm', 'LPM') }} matched key {{ key.sai_key_name }}
{% if key.sai_key_type == 'sai_object_id_t' %}
*
* @objects SAI_OBJECT_TYPE_{{ key.objectName | upper }}
{% endif %}
*/
{% if key.match_type == 'lpm' %}
{{ key.sai_lpm_type }} {{ key.sai_key_name | lower }};
{% elif key.match_type == 'list' %}
{{ key.sai_list_type }} {{ key.sai_key_name | lower }};
{% elif key.match_type == 'range_list' %}
{{ key.sai_range_list_type }} {{ key.sai_key_name | lower }};
{% elif key.match_type == 'optional' %}
{{ key.sai_key_type }} {{ key.sai_key_name | lower }};
{% else %}
{{ key.sai_key_type }} {{ key.sai_key_name | lower }};
{% endif %}
{% if key.match_type == 'ternary' %}
/**
* @brief Ternary key {{ key.sai_key_name }} mask
*/
{{ key.sai_key_type }} {{ key.sai_key_name | lower }}_mask;
{% endif %}
{% endfor %}
{% if table['keys'] | selectattr('match_type', 'ne', 'exact') | list | length > 0 %}
{% if table['keys'] | selectattr('match_type', 'eq', 'lpm') | list | length == 0 %}
/**
* @brief Rule priority in table
*/
sai_uint32_t priority;
{% endif %}
{% endif %}
} sai_{{ table.name }}_t;
{% endif %}
/**
* @brief Attribute ID for {{ sai_api.app_name }}_{{ table.name }}
*/
typedef enum _sai_{{ table.name }}_attr_t
{
/**
* @brief Start of attributes
*/
SAI_{{ table.name | upper }}_ATTR_START,
{% set ns = namespace(firstattr=false) %}
{% if table.actions | length > 1 or ((table.actions | length == 1) and (((table.is_object == 'false') or (table['keys'] | length <= 1)) and ((table['actionParams'] | length == 0)))) %}
/**
* @brief Action
*
* @type sai_{{ table.name }}_action_t
* @flags CREATE_AND_SET
* @default SAI_{{ table.name | upper }}_ACTION_{{ table.actions[0].name | upper }}
*/
SAI_{{ table.name | upper }}_ATTR_ACTION = SAI_{{ table.name | upper }}_ATTR_START,
{% set ns.firstattr = true %}
{% endif %}
{% if table.is_object == 'true' %}
{% if table['keys'] | length > 1 %}
{% for key in table['keys'] %}
/**
* @brief {{ key.match_type | capitalize | replace('Lpm', 'LPM') }} matched key {{ key.sai_key_name }}
*
{% if key.match_type == 'lpm' %}
* @type {{ key.sai_lpm_type }}
{% elif key.match_type == 'list' %}
* @type {{ key.sai_list_type }}
{% elif key.match_type == 'range_list' %}
* @type {{ key.sai_range_list_type }}
{% else %}
* @type {{ key.sai_key_type }}
{% endif %}
* @flags MANDATORY_ON_CREATE | CREATE_ONLY
{% if key.sai_key_type == 'sai_uint16_t' %}
* @isvlan false
{% endif %}
{% if key.sai_key_type == 'sai_object_id_t' %}
* @objects SAI_OBJECT_TYPE_{{ key.sai_key_name | replace('_id', '') | upper }}
{% endif %}
*/
{% if not ns.firstattr %}
SAI_{{ table.name | upper }}_ATTR_{{ key.sai_key_name | upper }} = SAI_{{ table.name | upper }}_ATTR_START,
{% set ns.firstattr = true %}
{% else %}
SAI_{{ table.name | upper }}_ATTR_{{ key.sai_key_name | upper }},
{% endif %}
{% if key.match_type == 'ternary' %}
/**
* @brief Ternary matched mask {{ key.sai_key_name }}
*
{% if key.match_type == 'list' %}
* @type {{ key.sai_list_type }}
{% elif key.match_type == 'range_list' %}
* @type {{ key.sai_range_list_type }}
{% else %}
* @type {{ key.sai_key_type }}
{% endif %}
* @flags MANDATORY_ON_CREATE | CREATE_ONLY
*/
SAI_{{ table.name | upper }}_ATTR_{{ key.sai_key_name | upper }}_MASK,
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% for param in table.actionParams %}
/**
* @brief Action {% for action in param.paramActions %}{{ action }}{{ ", " if not loop.last else "" }}{% endfor %} parameter {{ param.name | upper }}
*
* @type {{ param.type }}
* @flags CREATE_AND_SET
{% if param.type == 'sai_uint16_t' %}
* @isvlan false
{% endif %}
{% if param.type == 'sai_ip_address_t' %}
* @default 0.0.0.0
{% elif param.type == 'sai_ip_addr_family_t' %}
* @default SAI_IP_ADDR_FAMILY_IPV4
{% elif param.type == 'sai_mac_t' %}
* @default 0:0:0:0:0:0
{% elif param.type == 'bool' %}
* @default false
{% elif param.type == 'sai_object_id_t' %}
* @objects SAI_OBJECT_TYPE_{{ param.objectName | upper }}
* @allownull true
* @default SAI_NULL_OBJECT_ID
{% else %}
* @default 0
{% endif %}
{% if table.actions | length > 1 %}
{% if param.paramActions | length > 0 %}
* @validonly {% for action in param.paramActions %}SAI_{{ table.name | upper }}_ATTR_ACTION == SAI_{{ table.name | upper }}_ACTION_{{ action | upper }}{{ " or " if not loop.last else "" }}{% endfor %}
{% endif %}
{% endif %}
*/
{% if not ns.firstattr %}
SAI_{{ table.name | upper }}_ATTR_{{ param.name | upper }} = SAI_{{ table.name | upper }}_ATTR_START,
{% set ns.firstattr = true %}
{% else %}
SAI_{{ table.name | upper }}_ATTR_{{ param.name | upper }},
{% endif %}
{% endfor %}
{% if table.with_counters == 'true' %}
/**
* @brief Attach a counter
*
* When it is empty, then packet hits won't be counted
*
* @type sai_object_id_t
* @flags CREATE_AND_SET
* @objects SAI_OBJECT_TYPE_COUNTER
* @allownull true
* @default SAI_NULL_OBJECT_ID
*/
SAI_{{ table.name | upper }}_ATTR_COUNTER_ID,
{% endif %}
{% if table.is_object == 'true' %}
{% if table['keys'] | selectattr('match_type', 'ne', 'exact') | list | length > 0 %}
{% if table['keys'] | selectattr('match_type', 'eq', 'lpm') | list | length == 0 %}
/**
* @brief Rule priority in table
*
* @type sai_uint32_t
* @flags MANDATORY_ON_CREATE | CREATE_ONLY
*/
SAI_{{ table.name | upper }}_ATTR_PRIORITY,
{% endif %}
{% endif %}
{% endif %}
{% if table.ipaddr_family_attr == 'true' %}
/**
* @brief IP address family for resource accounting
*
* @type sai_ip_addr_family_t
* @flags READ_ONLY
* @isresourcetype true
*/
SAI_{{ table.name | upper }}_ATTR_IP_ADDR_FAMILY,
{% endif %}
/**
* @brief End of attributes
*/
SAI_{{ table.name | upper }}_ATTR_END,
/** Custom range base value */
SAI_{{ table.name | upper }}_ATTR_CUSTOM_RANGE_START = 0x10000000,
/** End of custom range base */
SAI_{{ table.name | upper }}_ATTR_CUSTOM_RANGE_END,
} sai_{{ table.name }}_attr_t;
{% endfor %}
{% for table in sai_api.tables %}
/**
* @brief Create {{ sai_api.app_name }}_{{ table.name }}
*
{% if table.is_object == 'true' %}
* @param[out] {{ table.name }}_id Entry id
* @param[in] switch_id Switch id
{% else %}
* @param[in] {{ table.name }} Entry
{% endif %}
* @param[in] attr_count Number of attributes
* @param[in] attr_list Array of attributes
*
* @return #SAI_STATUS_SUCCESS on success Failure status code on error
*/
typedef sai_status_t (*sai_create_{{ table.name }}_fn)(
{% if table.is_object == 'true' %}
_Out_ sai_object_id_t *{{ table.name }}_id,
_In_ sai_object_id_t switch_id,
{% else %}
_In_ const sai_{{ table.name }}_t *{{ table.name }},
{% endif %}
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);
/**
* @brief Remove {{ sai_api.app_name }}_{{ table.name }}
*
{% if table.is_object == 'true' %}
* @param[in] {{ table.name }}_id Entry id
{% else %}
* @param[in] {{ table.name }} Entry
{% endif %}
*
* @return #SAI_STATUS_SUCCESS on success Failure status code on error
*/
typedef sai_status_t (*sai_remove_{{ table.name }}_fn)(
{% if table.is_object == 'true' %}
_In_ sai_object_id_t {{ table.name }}_id);
{% else %}
_In_ const sai_{{ table.name }}_t *{{ table.name }});
{% endif %}
/**
* @brief Set attribute for {{ sai_api.app_name }}_{{ table.name }}
*
{% if table.is_object == 'true' %}
* @param[in] {{ table.name }}_id Entry id
{% else %}
* @param[in] {{ table.name }} Entry
{% endif %}
* @param[in] attr Attribute
*
* @return #SAI_STATUS_SUCCESS on success Failure status code on error
*/
typedef sai_status_t (*sai_set_{{ table.name }}_attribute_fn)(
{% if table.is_object == 'true' %}
_In_ sai_object_id_t {{ table.name }}_id,
{% else %}
_In_ const sai_{{ table.name }}_t *{{ table.name }},
{% endif %}
_In_ const sai_attribute_t *attr);
/**
* @brief Get attribute for {{ sai_api.app_name }}_{{ table.name }}
*
{% if table.is_object == 'true' %}
* @param[in] {{ table.name }}_id Entry id
{% else %}
* @param[in] {{ table.name }} Entry
{% endif %}
* @param[in] attr_count Number of attributes
* @param[inout] attr_list Array of attributes
*
* @return #SAI_STATUS_SUCCESS on success Failure status code on error
*/
typedef sai_status_t (*sai_get_{{ table.name }}_attribute_fn)(
{% if table.is_object == 'true' %}
_In_ sai_object_id_t {{ table.name }}_id,
{% else %}
_In_ const sai_{{ table.name }}_t *{{ table.name }},
{% endif %}
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list);
{% if table.is_object == 'false' %}
/**
* @brief Bulk create {{ sai_api.app_name }}_{{ table.name }}
*
* @param[in] object_count Number of objects to create
* @param[in] {{ table.name }} List of object to create
* @param[in] attr_count List of attr_count. Caller passes the number
* of attribute for each object to create.
* @param[in] attr_list List of attributes for every object.
* @param[in] mode Bulk operation error handling mode.
* @param[out] object_statuses List of status for every object. Caller needs to
* allocate the buffer
*
* @return #SAI_STATUS_SUCCESS on success when all objects are created or
* #SAI_STATUS_FAILURE when any of the objects fails to create. When there is
* failure, Caller is expected to go through the list of returned statuses to
* find out which fails and which succeeds.
*/
typedef sai_status_t (*sai_bulk_create_{{ table.name }}_fn)(
_In_ uint32_t object_count,
_In_ const sai_{{ table.name }}_t *{{ table.name }},
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);
/**
* @brief Bulk remove {{ sai_api.app_name }}_{{ table.name }}
*
* @param[in] object_count Number of objects to remove
* @param[in] {{ table.name }} List of objects to remove
* @param[in] mode Bulk operation error handling mode.
* @param[out] object_statuses List of status for every object. Caller needs to
* allocate the buffer
*
* @return #SAI_STATUS_SUCCESS on success when all objects are removed or
* #SAI_STATUS_FAILURE when any of the objects fails to remove. When there is
* failure, Caller is expected to go through the list of returned statuses to
* find out which fails and which succeeds.
*/
typedef sai_status_t (*sai_bulk_remove_{{ table.name }}_fn)(
_In_ uint32_t object_count,
_In_ const sai_{{ table.name }}_t *{{ table.name }},
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);
{% endif %}
{% endfor %}
typedef struct _sai_{{ sai_api.app_name }}_api_t
{
{% set table_name_max = sai_api.tables|map(attribute="name")|map("length") | max %}
{% for table in sai_api.tables %}
{% set space_offset = table_name_max - table.name | length %}
sai_create_{{ table.name }}_fn {{ " " * space_offset }}create_{{ table.name }};
sai_remove_{{ table.name }}_fn {{ " " * space_offset }}remove_{{ table.name }};
sai_set_{{ table.name }}_attribute_fn {{ " " * space_offset }}set_{{ table.name }}_attribute;
sai_get_{{ table.name }}_attribute_fn {{ " " * space_offset }}get_{{ table.name }}_attribute;
{% if table.is_object == 'true' %}
sai_bulk_object_create_fn{{ " " * table_name_max }}create_{{ table.name }}s;
sai_bulk_object_remove_fn{{ " " * table_name_max }}remove_{{ table.name }}s;
{% else %}
sai_bulk_create_{{ table.name }}_fn {{ " " * space_offset }}create_{{ table.name | replace("entry", "entries") }};
sai_bulk_remove_{{ table.name }}_fn {{ " " * space_offset }}remove_{{ table.name | replace("entry", "entries") }};
{% endif %}
{% endfor %}
} sai_{{ sai_api.app_name }}_api_t;
/**
* @}
*/
#endif /** __SAIEXPERIMENTAL{{ sai_api.app_name | replace('_', '') | upper}}_H_ */