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