P4C
The P4 Compiler
Loading...
Searching...
No Matches
psa_model.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_ARCH_PSA_PSA_MODEL_H_
20#define BACKENDS_TOFINO_BF_P4C_ARCH_PSA_PSA_MODEL_H_
21
22#include "frontends/common/model.h"
23#include "frontends/p4/coreLibrary.h"
24
25namespace BFN {
26
27namespace PSA {
28
29// The following should be kept in sync with tna.p4
30struct PacketPathType_Model : public ::Model::Enum_Model {
32 : ::Model::Enum_Model("PSA_PacketPath_t"_cs),
33 normal("NORMAL"_cs),
34 normal_unicast("NORMAL_UNICAST"_cs),
35 normal_multicast("NORMAL_MULTICAST"_cs),
36 clone_i2e("CLONE_I2E"_cs),
37 clone_e2e("CLONE_E2E"_cs),
38 resubmit("RESUBMIT"_cs),
39 recirculate("RECIRCULATE"_cs) {}
40 ::Model::Elem normal;
41 ::Model::Elem normal_unicast;
42 ::Model::Elem normal_multicast;
43 ::Model::Elem clone_i2e;
44 ::Model::Elem clone_e2e;
45 ::Model::Elem resubmit;
46 ::Model::Elem recirculate;
47};
48
49struct MeterType_Model : public ::Model::Enum_Model {
51 : ::Model::Enum_Model("PSA_MeterType_t"_cs), packets("PACKETS"_cs), bytes("PACKETS"_cs) {}
52 ::Model::Elem packets;
53 ::Model::Elem bytes;
54};
55
56struct MeterColor_Model : public ::Model::Enum_Model {
58 : ::Model::Enum_Model("PSA_MeterColor_t"_cs),
59 green("GREEN"_cs),
60 yellow("YELLOW"_cs),
61 red("RED"_cs) {}
62 ::Model::Elem green;
63 ::Model::Elem yellow;
64 ::Model::Elem red;
65};
66
67struct CounterType_Model : public ::Model::Enum_Model {
69 : ::Model::Enum_Model("PSA_CounterType_t"_cs),
70 packets("PACKETS"_cs),
71 bytes("BYTES"_cs),
72 both("PACKETS_AND_BYTES"_cs) {}
73 ::Model::Elem packets;
74 ::Model::Elem bytes;
75 ::Model::Elem both;
76};
77
78struct HashAlgorithmType_Model : public ::Model::Enum_Model {
80 : ::Model::Enum_Model("PSA_HashAlgorithm_t"_cs),
81 identify("IDENTITY"_cs),
82 crc16("CRC16"_cs),
83 crc16_custom("CRC16_CUSTOM"_cs),
84 crc32("CRC32"_cs),
85 crc32_custom("CRC32_CUSTOM"_cs),
86 ones_complement16("ONES_COMPLEMENT16"_cs),
87 target_default("TARGET_DEFAULT"_cs) {}
88 ::Model::Elem identify;
89 ::Model::Elem crc16;
90 ::Model::Elem crc16_custom;
91 ::Model::Elem crc32;
92 ::Model::Elem crc32_custom;
93 ::Model::Elem ones_complement16;
94 ::Model::Elem target_default;
95};
96
97struct IngressParserInputMetaType_Model : public ::Model::Type_Model {
99 : ::Model::Type_Model("psa_ingress_parser_input_metadata_t"_cs),
100 ingress_port("ingress_port"_cs),
101 packet_path("packet_path"_cs) {}
102 ::Model::Elem ingress_port;
103 ::Model::Elem packet_path;
104};
105
106struct EgressParserInputMetaType_Model : public ::Model::Type_Model {
108 : ::Model::Type_Model("psa_egress_parser_input_metadata_t"_cs),
109 egress_port("egress_port"_cs),
110 packet_path("packet_path"_cs) {}
111 ::Model::Elem egress_port;
112 ::Model::Elem packet_path;
113};
114
115struct IngressInputMetaType_Model : public ::Model::Type_Model {
117 : ::Model::Type_Model("psa_ingress_input_metadata_t"_cs),
118 ingress_port("ingress_port"_cs),
119 packet_path("packet_path"_cs),
120 ingress_timestamp("ingress_timestamp"_cs),
121 parser_error("parser_error"_cs) {}
122 ::Model::Elem ingress_port;
123 ::Model::Elem packet_path;
124 ::Model::Elem ingress_timestamp;
125 ::Model::Elem parser_error;
126};
127
128struct IngressOutputMetaType_Model : public ::Model::Type_Model {
130 : ::Model::Type_Model("psa_ingress_output_metadata_t"_cs),
131 class_of_service("class_of_service"_cs),
132 clone("clone"_cs),
133 clone_session_id("clone_session_id"_cs),
134 drop("drop"_cs),
135 resubmit("resubmit"_cs),
136 multicast_group("multicast_group"_cs),
137 egress_port("egress_port"_cs) {}
138 ::Model::Elem class_of_service;
139 ::Model::Elem clone;
140 ::Model::Elem clone_session_id;
141 ::Model::Elem drop;
142 ::Model::Elem resubmit;
143 ::Model::Elem multicast_group;
144 ::Model::Elem egress_port;
145};
146
147struct EgressInputMetaType_Model : public ::Model::Type_Model {
149 : ::Model::Type_Model("psa_egress_input_metadata_t"_cs),
150 class_of_service("class_of_service"_cs),
151 egress_port("egress_port"_cs),
152 packet_path("packet_path"_cs),
153 instance("instance"_cs),
154 egress_timestamp("egress_timestamp"_cs),
155 parser_error("parser_error"_cs) {}
156 ::Model::Elem class_of_service;
157 ::Model::Elem egress_port;
158 ::Model::Elem packet_path;
159 ::Model::Elem instance;
160 ::Model::Elem egress_timestamp;
161 ::Model::Elem parser_error;
162};
163
164struct EgressDeparserInputMetaType_Model : public ::Model::Type_Model {
166 : ::Model::Type_Model("psa_egress_deparser_input_metadata_t"_cs),
167 egress_port("egress_port"_cs) {}
168 ::Model::Elem egress_port;
169};
170
171struct EgressOutputMetaType_Model : public ::Model::Type_Model {
173 : ::Model::Type_Model("psa_egress_output_metadata_t"_cs),
174 clone("clone"_cs),
175 clone_session_id("clone_session_id"_cs),
176 drop("drop"_cs) {}
177 ::Model::Elem clone;
178 ::Model::Elem clone_session_id;
179 ::Model::Elem drop;
180};
181
182struct CompilerGeneratedMetaType_Model : public ::Model::Type_Model {
184 : ::Model::Type_Model("compiler_generated_metadata_t"_cs),
185 instance_name(name),
186 mirror_id("mirror_id"_cs),
187 mirror_source("mirror_source"_cs),
188 clone_src("clone_src"_cs),
189 clone_digest_id("clone_digest_id"_cs) {}
190 ::Model::Elem instance_name;
191 ::Model::Elem mirror_id;
192 ::Model::Elem mirror_source;
193 ::Model::Elem clone_src;
194 ::Model::Elem clone_digest_id;
195};
196
197struct Checksum_Model : public ::Model::Extern_Model {
199 : Extern_Model("Checksum"_cs), clear("clear"_cs), update("update"_cs), get("get"_cs) {}
200 HashAlgorithmType_Model algorithm;
201 ::Model::Elem clear;
202 ::Model::Elem update;
203 ::Model::Elem get;
204};
205
206struct InternetChecksum_Model : public ::Model::Extern_Model {
208 : Extern_Model("InternetChecksum"_cs),
209 clear("clear"_cs),
210 add("add"_cs),
211 subtract("subtract"_cs),
212 get("get"_cs),
213 get_state("get_state"_cs),
214 set_state("set_state"_cs) {}
215 HashAlgorithmType_Model algorithm;
216 ::Model::Elem clear;
217 ::Model::Elem add;
218 ::Model::Elem subtract;
219 ::Model::Elem get;
220 ::Model::Elem get_state;
221 ::Model::Elem set_state;
222};
223
224struct Hash_Model : public ::Model::Extern_Model {
225 Hash_Model() : Extern_Model("Hash"_cs), get("get"_cs), get_with_base("get"_cs) {}
226 HashAlgorithmType_Model algorithm;
227 ::Model::Elem get;
228 ::Model::Elem get_with_base;
229};
230
231struct Random_Model : public ::Model::Extern_Model {
232 Random_Model() : Extern_Model("Random"_cs), get("get"_cs) {}
233 ::Model::Elem get;
234};
235
236struct Counter_Model : public ::Model::Extern_Model {
237 Counter_Model() : Extern_Model("Counter"_cs), counterType(), count("count"_cs) {}
238 CounterType_Model counterType;
239 ::Model::Elem count;
240};
241
242struct DirectCounter_Model : public ::Model::Extern_Model {
243 DirectCounter_Model() : Extern_Model("DirectCounter"_cs), counterType(), count("count"_cs) {}
244 CounterType_Model counterType;
245 ::Model::Elem count;
246};
247
248struct Meter_Model : public ::Model::Extern_Model {
249 Meter_Model() : Extern_Model("Meter"_cs), meterType(), execute("execute"_cs) {}
250 MeterType_Model meterType;
251 ::Model::Elem execute;
252};
253
254struct DirectMeter_Model : public ::Model::Extern_Model {
255 DirectMeter_Model() : Extern_Model("DirectMeter"_cs), meterType(), execute("execute"_cs) {}
256 MeterType_Model meterType;
257 ::Model::Elem execute;
258};
259
260struct Register_Model : public ::Model::Extern_Model {
262 : Extern_Model("Register"_cs),
263 sizeParam("size"_cs),
264 size_type(IR::Type_Bits::get(32)),
265 read("read"_cs),
266 write("write"_cs) {}
267 ::Model::Elem sizeParam;
268 const IR::Type *size_type;
269 ::Model::Elem read;
270 ::Model::Elem write;
271};
272
273struct ActionProfile_Model : public ::Model::Extern_Model {
275 : Extern_Model("ActionProfile"_cs),
276 sizeType(IR::Type_Bits::get(32)),
277 sizeParam("size"_cs) {}
278 const IR::Type *sizeType;
279 ::Model::Elem sizeParam;
280};
281
282struct ActionSelector_Model : public ::Model::Extern_Model {
284 : Extern_Model("ActionSelector"_cs),
285 hashType(),
286 sizeType(IR::Type_Bits::get(32)),
287 sizeParam("size"_cs),
288 outputWidthType(IR::Type_Bits::get(32)),
289 outputWidthParam("outputWidth"_cs) {}
291 const IR::Type *sizeType;
292 ::Model::Elem sizeParam;
293 const IR::Type *outputWidthType;
294 ::Model::Elem outputWidthParam;
295};
296
297struct Digest_Model : public ::Model::Extern_Model {
298 Digest_Model() : Extern_Model("Digest"_cs), pack("pack"_cs) {}
299 ::Model::Elem pack;
300};
301
304 : tableImplementation("implementation"_cs),
305 counters("counters"_cs),
306 meters("meters"_cs),
307 size("size"_cs),
308 supportTimeout("support_timeout"_cs) {}
309 ::Model::Elem tableImplementation;
310 ::Model::Elem counters;
311 ::Model::Elem meters;
312 ::Model::Elem size;
313 ::Model::Elem supportTimeout;
314 const unsigned defaultTableSize = 1024;
315};
316
317struct IngressParserModel : public ::Model::Elem {
319 Model::Type_Model istdType, Model::Type_Model resubmitMetaType,
320 Model::Type_Model recircMetaType)
321 : Model::Elem("IngressParser"_cs),
322 packetParam("buffer"_cs, P4::P4CoreLibrary::instance().packetIn, 0),
323 headersParam("parsed_hdr"_cs, headersType, 1),
324 metadataParam("user_meta"_cs, userMetaType, 2),
325 istdParam("istd"_cs, istdType, 3),
326 resubmitParam("resubmit_meta"_cs, resubmitMetaType, 4),
327 recircParam("recirculate_meta"_cs, recircMetaType, 5) { /* empty */ }
328 ::Model::Param_Model packetParam;
329 ::Model::Param_Model headersParam;
330 ::Model::Param_Model metadataParam;
331 ::Model::Param_Model istdParam;
332 ::Model::Param_Model resubmitParam;
333 ::Model::Param_Model recircParam;
334};
335
336struct IngressModel : public ::Model::Elem {
337 IngressModel(Model::Type_Model headersType, Model::Type_Model userMetaType,
338 Model::Type_Model istdType, Model::Type_Model ostdType)
339 : Model::Elem("Ingress"_cs),
340 headersParam("hdr"_cs, headersType, 0),
341 metadataParam("user_meta"_cs, userMetaType, 1),
342 istdParam("istd"_cs, istdType, 2),
343 ostdParam("ostd"_cs, ostdType, 3) { /* empty */ }
344 ::Model::Param_Model headersParam;
345 ::Model::Param_Model metadataParam;
346 ::Model::Param_Model istdParam;
347 ::Model::Param_Model ostdParam;
348};
349
350struct IngressDeparserModel : public ::Model::Elem {
351 IngressDeparserModel(Model::Type_Model cloneType, Model::Type_Model resubmitMetaType,
352 Model::Type_Model bridgeMetaType, Model::Type_Model headersType,
353 Model::Type_Model userMetaType, Model::Type_Model istdType)
354 : Model::Elem("IngressDeparser"_cs),
355 packetParam("buffer"_cs, P4::P4CoreLibrary::instance().packetIn, 0),
356 cloneParam("clone_i2e_meta"_cs, cloneType, 1),
357 resubmitParam("resubmit_meta"_cs, resubmitMetaType, 2),
358 normalMetaParam("normal_meta"_cs, bridgeMetaType, 3),
359 headersParam("hdr"_cs, headersType, 4),
360 metadataParam("meta"_cs, userMetaType, 5),
361 istdParam("istd"_cs, istdType, 6) { /* empty */ }
362 ::Model::Param_Model packetParam;
363 ::Model::Param_Model cloneParam;
364 ::Model::Param_Model resubmitParam;
365 ::Model::Param_Model normalMetaParam;
366 ::Model::Param_Model headersParam;
367 ::Model::Param_Model metadataParam;
368 ::Model::Param_Model istdParam;
369};
370
371struct EgressParserModel : public ::Model::Elem {
372 EgressParserModel(Model::Type_Model headersType, Model::Type_Model userMetaType,
373 Model::Type_Model istdMetaType, Model::Type_Model bridgeMetaType,
374 Model::Type_Model cloneI2EMetaType, Model::Type_Model cloneE2EMetaType)
375 : Model::Elem("EgressParser"_cs),
376 packetParam("buffer"_cs, P4::P4CoreLibrary::instance().packetIn, 0),
377 headersParam("parsed_hdr"_cs, headersType, 1),
378 metadataParam("user_meta"_cs, userMetaType, 2),
379 istdMetaParam("istd"_cs, istdMetaType, 3),
380 normalMetaParam("normal_meta"_cs, bridgeMetaType, 4),
381 cloneI2EMetaParam("clone_i2e_meta"_cs, cloneI2EMetaType, 5),
382 cloneE2EMetaParam("clone_e2e_meta"_cs, cloneE2EMetaType, 6) { /* empty */ }
383 ::Model::Param_Model packetParam;
384 ::Model::Param_Model headersParam;
385 ::Model::Param_Model metadataParam;
386 ::Model::Param_Model istdMetaParam;
387 ::Model::Param_Model normalMetaParam;
388 ::Model::Param_Model cloneI2EMetaParam;
389 ::Model::Param_Model cloneE2EMetaParam;
390};
391
392struct EgressModel : public ::Model::Elem {
393 EgressModel(Model::Type_Model headersType, Model::Type_Model userMetaType,
394 Model::Type_Model istdType, Model::Type_Model ostdType)
395 : Model::Elem("Egress"_cs),
396 headersParam("hdr"_cs, headersType, 0),
397 metadataParam("user_meta"_cs, userMetaType, 1),
398 istdParam("istd"_cs, istdType, 2),
399 ostdParam("ostd"_cs, ostdType, 3) { /* empty */ }
400 ::Model::Param_Model headersParam;
401 ::Model::Param_Model metadataParam;
402 ::Model::Param_Model istdParam;
403 ::Model::Param_Model ostdParam;
404};
405
406struct EgressDeparserModel : public ::Model::Elem {
407 EgressDeparserModel(Model::Type_Model cloneE2EMetaType, Model::Type_Model recircMetaType,
408 Model::Type_Model headersType, Model::Type_Model userMetaType,
409 Model::Type_Model istdType, Model::Type_Model edstdType)
410 : Model::Elem("EgressDeparser"_cs),
411 packetParam("buffer"_cs, P4::P4CoreLibrary::instance().packetIn, 0),
412 cloneE2EMetaParam("clone_e2e_meta"_cs, cloneE2EMetaType, 1),
413 recircMetaParam("recirculate_meta"_cs, recircMetaType, 2),
414 headersParam("hdr"_cs, headersType, 3),
415 metadataParam("meta"_cs, userMetaType, 4),
416 istdParam("istd"_cs, istdType, 5),
417 edstdParam("edstd"_cs, edstdType, 6) { /* empty */ }
418 ::Model::Param_Model packetParam;
419 ::Model::Param_Model cloneE2EMetaParam;
420 ::Model::Param_Model recircMetaParam;
421 ::Model::Param_Model headersParam;
422 ::Model::Param_Model metadataParam;
423 ::Model::Param_Model istdParam;
424 ::Model::Param_Model edstdParam;
425};
426
427struct Pipeline : public ::Model::Elem {
428 explicit Pipeline(cstring name)
429 : Model::Elem(name),
430 ingressParser("ingress_parser"_cs),
431 ingress("ingress"_cs),
432 ingressDeparser("ingress_deparser"_cs),
433 packetReplicationEngine("pre"_cs),
434 egressParser("egress_parser"_cs),
435 egress("egress"_cs),
436 egressDeparser("egress_deparser"_cs),
437 bufferingQueueingEngine("bqe"_cs) { /* empty */ }
438 ::Model::Elem ingressParser;
439 ::Model::Elem ingress;
440 ::Model::Elem ingressDeparser;
441 ::Model::Elem packetReplicationEngine;
442 ::Model::Elem egressParser;
443 ::Model::Elem egress;
444 ::Model::Elem egressDeparser;
445 ::Model::Elem bufferingQueueingEngine;
446};
447
448// must be kept consistent with psa.p4
449class PsaModel : public ::Model::Model {
450 protected:
451 PsaModel()
452 : Model::Model(),
453 file("psa.p4"_cs),
454 headersType("headers"_cs),
455 metadataType("metadata"_cs),
456 resubmitMetaType("resubmit_meta"_cs),
457 recircMetaType("recirc_meta"_cs),
458 cloneI2EMetaType("clone_i2e_meta"_cs),
459 cloneE2EMetaType("clone_e2e_meta"_cs),
460 bridgeMetaType("bridge_meta"_cs),
461 compilerGeneratedType("compiler_generated_meta"_cs),
462 ingress_parser(headersType, metadataType, igParserInputMetaType, resubmitMetaType,
463 recircMetaType),
464 ingress(headersType, metadataType, igInputMetaType, igOutputMetaType),
465 ingress_deparser(cloneI2EMetaType, resubmitMetaType, bridgeMetaType, headersType,
466 metadataType, igOutputMetaType),
467 egress_parser(headersType, metadataType, egParserInputMetaType, bridgeMetaType,
468 cloneI2EMetaType, cloneE2EMetaType),
469 egress(headersType, metadataType, egInputMetaType, egOutputMetaType),
470 egress_deparser(cloneE2EMetaType, recircMetaType, headersType, metadataType,
471 egOutputMetaType, egDeparserInputMetaType),
472 sw("Switch"_cs) { /* empty */ }
473
474 public:
475 ::Model::Elem file;
476 ::Model::Type_Model headersType;
477 ::Model::Type_Model metadataType;
478
479 IngressParserInputMetaType_Model igParserInputMetaType;
480 IngressInputMetaType_Model igInputMetaType;
481 IngressOutputMetaType_Model igOutputMetaType;
482 EgressParserInputMetaType_Model egParserInputMetaType;
483 EgressInputMetaType_Model egInputMetaType;
484 EgressOutputMetaType_Model egOutputMetaType;
485 EgressDeparserInputMetaType_Model egDeparserInputMetaType;
486
487 ::Model::Type_Model resubmitMetaType;
488 ::Model::Type_Model recircMetaType;
489 ::Model::Type_Model cloneI2EMetaType;
490 ::Model::Type_Model cloneE2EMetaType;
491 ::Model::Type_Model bridgeMetaType;
492
493 CompilerGeneratedMetaType_Model compilerGeneratedType;
494
495 // blocks
496 IngressParserModel ingress_parser;
497 IngressModel ingress;
498 IngressDeparserModel ingress_deparser;
499 EgressParserModel egress_parser;
500 EgressModel egress;
501 EgressDeparserModel egress_deparser;
502
503 // pipelines
504 Pipeline sw;
505
506 // externs
507 ActionProfile_Model action_profile;
508 ActionSelector_Model action_selector;
509 Checksum_Model checksum;
510 Counter_Model counter;
511 DirectCounter_Model directCounter;
512 DirectMeter_Model directMeter;
513 Hash_Model hash;
514 Meter_Model meter;
515 Random_Model random;
516 Register_Model registers;
517
518 // tables
519 TableAttributes_Model tableAttributes;
520
521 static PsaModel instance;
522};
523
524} // namespace PSA
525
526} // namespace BFN
527
528#endif /* BACKENDS_TOFINO_BF_P4C_ARCH_PSA_PSA_MODEL_H_ */
Definition psa_model.h:449
Definition frontends/common/model.h:64
Definition cstring.h:85
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
Definition psa_model.h:273
Definition psa_model.h:282
Definition psa_model.h:197
Definition psa_model.h:236
Definition psa_model.h:67
Definition psa_model.h:297
Definition psa_model.h:242
Definition psa_model.h:254
Definition psa_model.h:406
Definition psa_model.h:147
Definition psa_model.h:392
Definition psa_model.h:171
Definition psa_model.h:371
Definition psa_model.h:224
Definition psa_model.h:78
Definition psa_model.h:350
Definition psa_model.h:115
Definition psa_model.h:336
Definition psa_model.h:128
Definition psa_model.h:317
Definition psa_model.h:206
Definition psa_model.h:248
Definition psa_model.h:56
Definition psa_model.h:49
Definition psa_model.h:30
Definition psa_model.h:427
Definition psa_model.h:231
Definition psa_model.h:260
Definition psa_model.h:302
Definition frontends/common/model.h:28
Definition frontends/common/model.h:42