P4C
The P4 Compiler
Loading...
Searching...
No Matches
frontends/p4-14/fromv1.0/v1model.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef FRONTENDS_P4_14_FROMV1_0_V1MODEL_H_
18#define FRONTENDS_P4_14_FROMV1_0_V1MODEL_H_
19
20#include "frontends/common/model.h"
21#include "frontends/p4/coreLibrary.h"
22#include "ir/ir.h"
23#include "lib/cstring.h"
24
25namespace P4::P4V1 {
26
27using namespace P4::literals;
28
29// This should be kept in sync with p4includes/v1model.p4
30// In a perfect world this would be generated automatically from
31// p4includes/v1model.p4
32
34 Parser_Model(Model::Type_Model headersType, Model::Type_Model userMetaType,
35 Model::Type_Model standardMetadataType)
36 : Model::Elem("ParserImpl"_cs),
37 packetParam("packet"_cs, P4::P4CoreLibrary::instance().packetIn, 0),
38 headersParam("hdr"_cs, headersType, 1),
39 metadataParam("meta"_cs, userMetaType, 2),
40 standardMetadataParam("standard_metadata"_cs, standardMetadataType, 3) {}
41 ::P4::Model::Param_Model packetParam;
42 ::P4::Model::Param_Model headersParam;
43 ::P4::Model::Param_Model metadataParam;
44 ::P4::Model::Param_Model standardMetadataParam;
45};
46
48 explicit Deparser_Model(Model::Type_Model headersType)
49 : Model::Elem("DeparserImpl"_cs),
50 packetParam("packet"_cs, P4::P4CoreLibrary::instance().packetOut, 0),
51 headersParam("hdr"_cs, headersType, 1) {}
52 ::P4::Model::Param_Model packetParam;
53 ::P4::Model::Param_Model headersParam;
54};
55
56// Models ingress and egress
58 Control_Model(cstring name, Model::Type_Model headersType, Model::Type_Model metadataType,
59 Model::Type_Model standardMetadataType)
60 : Model::Elem(name),
61 headersParam("hdr"_cs, headersType, 0),
62 metadataParam("meta"_cs, metadataType, 1),
63 standardMetadataParam("standard_metadata"_cs, standardMetadataType, 2) {}
64 ::P4::Model::Param_Model headersParam;
65 ::P4::Model::Param_Model metadataParam;
66 ::P4::Model::Param_Model standardMetadataParam;
67};
68
71 : Model::Elem(name), headersParam("hdr"_cs, headersType, 0) {}
72 ::P4::Model::Param_Model headersParam;
73};
74
77 : ::P4::Model::Enum_Model("CounterType"_cs),
78 packets("packets"_cs),
79 bytes("bytes"_cs),
80 both("packets_and_bytes"_cs) {}
81 ::P4::Model::Elem packets;
84};
85
88 : ::P4::Model::Enum_Model("MeterType"_cs), packets("packets"_cs), bytes("bytes"_cs) {}
89 ::P4::Model::Elem packets;
91};
92
95 : Extern_Model("action_profile"_cs),
96 sizeType(IR::Type_Bits::get(32)),
97 sizeParam("size"_cs) {}
98 const IR::Type *sizeType;
99 ::P4::Model::Elem sizeParam;
100};
101
104 : Extern_Model("action_selector"_cs),
105 sizeType(IR::Type_Bits::get(32)),
106 sizeParam("size"_cs),
107 widthType(IR::Type_Bits::get(32)),
108 algorithmParam("algorithm"_cs) {}
109 const IR::Type *sizeType;
110 ::P4::Model::Elem sizeParam;
111 const IR::Type *widthType;
112 ::P4::Model::Elem algorithmParam;
113};
114
116 Random_Model() : Elem("random"_cs), modify_field_rng_uniform("modify_field_rng_uniform"_cs) {}
117 ::P4::Model::Elem modify_field_rng_uniform;
118};
119
121 public:
122 Truncate() : Extern_Model("truncate"_cs), length_type(IR::Type::Bits::get(32)) {}
123 const IR::Type *length_type;
124};
125
127 explicit CounterOrMeter_Model(cstring name)
128 : Extern_Model(name),
129 sizeParam("size"_cs),
130 typeParam("type"_cs),
131 size_type(IR::Type_Bits::get(32)) {}
132 ::P4::Model::Elem sizeParam;
133 ::P4::Model::Elem typeParam;
134 const IR::Type *size_type;
135 CounterType_Model counterType;
136 MeterType_Model meterType;
137};
138
141 : Extern_Model("register"_cs),
142 sizeParam("size"_cs),
143 read("read"_cs),
144 write("write"_cs),
145 size_type(IR::Type_Bits::get(32)) {}
146 ::P4::Model::Elem sizeParam;
148 ::P4::Model::Elem write;
149 const IR::Type *size_type;
150};
151
153 DigestReceiver_Model() : Elem("digest"_cs), receiverType(IR::Type_Bits::get(32)) {}
154 const IR::Type *receiverType;
155};
156
158 Counter_Model() : CounterOrMeter_Model("counter"_cs), increment("count"_cs) {}
159 ::P4::Model::Elem increment;
160};
161
163 Meter_Model() : CounterOrMeter_Model("meter"_cs), executeMeter("execute_meter"_cs) {}
164 ::P4::Model::Elem executeMeter;
165};
166
168 DirectMeter_Model() : CounterOrMeter_Model("direct_meter"_cs), read("read"_cs) {}
170};
171
173 DirectCounter_Model() : CounterOrMeter_Model("direct_counter"_cs), count("count"_cs) {}
174 ::P4::Model::Elem count;
175};
176
180 dropBit("drop"_cs),
181 recirculate("recirculate_port"_cs),
182 egress_spec("egress_spec"_cs) {}
183 ::P4::Model::Elem dropBit;
184 ::P4::Model::Elem recirculate;
185 ::P4::Model::Elem egress_spec;
186};
187
189 CloneType_Model() : ::P4::Model::Enum_Model("CloneType"_cs), i2e("I2E"_cs), e2e("E2E"_cs) {}
192};
193
196 : ::P4::Model::Enum_Model("HashAlgorithm"_cs),
197 crc32("crc32"_cs),
198 crc32_custom("crc32_custom"_cs),
199 crc16("crc16"_cs),
200 crc16_custom("crc16_custom"_cs),
201 random("random"_cs),
202 identity("identity"_cs),
203 csum16("csum16"_cs),
204 xor16("xor16"_cs) {}
205 ::P4::Model::Elem crc32;
206 ::P4::Model::Elem crc32_custom;
207 ::P4::Model::Elem crc16;
208 ::P4::Model::Elem crc16_custom;
209 ::P4::Model::Elem random;
210 ::P4::Model::Elem identity;
211 ::P4::Model::Elem csum16;
212 ::P4::Model::Elem xor16;
213};
214
216 Hash_Model() : ::P4::Model::Elem("hash"_cs) {}
217};
218
221 : Extern_Model("clone"_cs),
222 clone3("clone_preserving_field_list"_cs),
223
224 sessionType(IR::Type_Bits::get(32)) {}
225 ::P4::Model::Elem clone3;
226 CloneType_Model cloneType;
227 const IR::Type *sessionType;
228};
229
232 : Model::Elem("V1Switch"_cs),
233 parser("p"_cs),
234 verify("vr"_cs),
235 ingress("ig"_cs),
236 egress("eg"_cs),
237 compute("ck"_cs),
238 deparser("dep"_cs) {}
239 ::P4::Model::Elem parser; // names of the package arguments
240 ::P4::Model::Elem verify;
241 ::P4::Model::Elem ingress;
242 ::P4::Model::Elem egress;
243 ::P4::Model::Elem compute;
244 ::P4::Model::Elem deparser;
245};
246
249 : tableImplementation("implementation"_cs),
250 counters("counters"_cs),
251 meters("meters"_cs),
252 size("size"_cs),
253 supportTimeout("support_timeout"_cs) {}
254 ::P4::Model::Elem tableImplementation;
255 ::P4::Model::Elem counters;
256 ::P4::Model::Elem meters;
258 ::P4::Model::Elem supportTimeout;
259 const unsigned defaultTableSize = 1024;
260};
261
262class V1Model : public Model::Model {
263 protected:
264 V1Model()
265 : file("v1model.p4"_cs),
266 standardMetadata("standard_metadata"_cs),
267 // The following 2 are not really docmented in the P4-14 spec.
268 intrinsicMetadata("intrinsic_metadata"_cs),
269 queueingMetadata("queueing_metadata"_cs),
270 headersType("headers"_cs),
271 metadataType("metadata"_cs),
272 standardMetadataType("standard_metadata_t"_cs),
273 parser(headersType, metadataType, standardMetadataType),
274 deparser(headersType),
275 egress("egress"_cs, headersType, metadataType, standardMetadataType),
276 ingress("ingress"_cs, headersType, metadataType, standardMetadataType),
277 sw(),
278 counterOrMeter("$"_cs),
279 counter(),
280 meter(),
281 random(),
282 action_profile(),
283 action_selector(),
284 clone(),
285 resubmit("resubmit_preserving_field_list"_cs),
286 tableAttributes(),
287 rangeMatchType("range"_cs),
288 optionalMatchType("optional"_cs),
289 selectorMatchType("selector"_cs),
290 verify("verifyChecksum"_cs, headersType),
291 compute("computeChecksum"_cs, headersType),
292 digest_receiver(),
293 hash(),
294 algorithm(),
295 registers(),
296 drop("mark_to_drop"_cs),
297 recirculate("recirculate_preserving_field_list"_cs),
298 verify_checksum("verify_checksum"_cs),
299 update_checksum("update_checksum"_cs),
300 verify_checksum_with_payload("verify_checksum_with_payload"_cs),
301 update_checksum_with_payload("update_checksum_with_payload"_cs),
302 log_msg("log_msg"_cs),
303 directMeter(),
304 directCounter() {}
305
306 public:
307 const ::P4::Model::Elem file;
308 const ::P4::Model::Elem standardMetadata;
309 const ::P4::Model::Elem intrinsicMetadata;
310 const ::P4::Model::Elem queueingMetadata;
311 const ::P4::Model::Type_Model headersType;
312 const ::P4::Model::Type_Model metadataType;
313 const StandardMetadataType_Model standardMetadataType;
314 const Parser_Model parser;
315 const Deparser_Model deparser;
316 const Control_Model egress;
317 const Control_Model ingress;
318 const Switch_Model sw;
319 const Truncate truncate;
320 const CounterOrMeter_Model counterOrMeter;
321 const Counter_Model counter;
322 const Meter_Model meter;
323 const Random_Model random;
324 const ActionProfile_Model action_profile;
325 const ActionSelector_Model action_selector;
326 const Cloner_Model clone;
327 const ::P4::Model::Elem resubmit;
328 const TableAttributes_Model tableAttributes;
329 const ::P4::Model::Elem rangeMatchType;
330 const ::P4::Model::Elem optionalMatchType;
331 const ::P4::Model::Elem selectorMatchType;
332 const VerifyUpdate_Model verify;
333 const VerifyUpdate_Model compute;
334 const DigestReceiver_Model digest_receiver;
335 const Hash_Model hash;
336 const Algorithm_Model algorithm;
337 const Register_Model registers;
338 const ::P4::Model::Elem drop;
339 const ::P4::Model::Elem recirculate;
340 const ::P4::Model::Elem verify_checksum;
341 const ::P4::Model::Elem update_checksum;
342 const ::P4::Model::Elem verify_checksum_with_payload;
343 const ::P4::Model::Elem update_checksum_with_payload;
344 const ::P4::Model::Elem log_msg;
345 const DirectMeter_Model directMeter;
346 const DirectCounter_Model directCounter;
347
348 static V1Model instance;
349 // The following match constants appearing in v1model.p4
350 static const char *versionInitial; // 20180101
351 static const char *versionCurrent; // 20200408
352};
353
354} // namespace P4::P4V1
355
356#endif /* FRONTENDS_P4_14_FROMV1_0_V1MODEL_H_ */
Definition frontends/common/model.h:64
Definition frontends/p4-14/fromv1.0/v1model.h:120
Definition frontends/p4-14/fromv1.0/v1model.h:262
Definition cstring.h:85
Definition converters.cpp:28
Definition cstring.h:80
Definition frontends/common/model.h:28
Enum_Model : Type_Model.
Definition frontends/common/model.h:47
Extern_Model : Type_Model.
Definition frontends/common/model.h:52
Param_Model : Elem.
Definition frontends/common/model.h:57
Definition frontends/common/model.h:42
Definition frontends/p4-14/fromv1.0/v1model.h:93
Definition frontends/p4-14/fromv1.0/v1model.h:102
Definition frontends/p4-14/fromv1.0/v1model.h:194
Definition frontends/p4-14/fromv1.0/v1model.h:188
Definition frontends/p4-14/fromv1.0/v1model.h:219
Definition frontends/p4-14/fromv1.0/v1model.h:57
Definition frontends/p4-14/fromv1.0/v1model.h:157
Definition frontends/p4-14/fromv1.0/v1model.h:126
Definition frontends/p4-14/fromv1.0/v1model.h:75
Definition frontends/p4-14/fromv1.0/v1model.h:47
Definition frontends/p4-14/fromv1.0/v1model.h:152
Definition frontends/p4-14/fromv1.0/v1model.h:172
Definition frontends/p4-14/fromv1.0/v1model.h:167
Definition frontends/p4-14/fromv1.0/v1model.h:215
Definition frontends/p4-14/fromv1.0/v1model.h:162
Definition frontends/p4-14/fromv1.0/v1model.h:86
Definition frontends/p4-14/fromv1.0/v1model.h:33
Definition frontends/p4-14/fromv1.0/v1model.h:115
Definition frontends/p4-14/fromv1.0/v1model.h:139
Definition frontends/p4-14/fromv1.0/v1model.h:177
Definition frontends/p4-14/fromv1.0/v1model.h:230
Definition frontends/p4-14/fromv1.0/v1model.h:247
Definition frontends/p4-14/fromv1.0/v1model.h:69