-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend_sai_model.h
327 lines (286 loc) · 11.8 KB
/
frontend_sai_model.h
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
/*
Copyright 2013-present Barefoot Networks, 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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _FRONTEND_SAI_MODEL_H_
#define _FRONTEND_SAI_MODEL_H_
#include "lib/cstring.h"
#include "frontends/common/model.h"
#include "frontends/p4/coreLibrary.h"
#include "frontends/p4/methodInstance.h"
#include "ir/ir.h"
#include "lib/json.h"
namespace P4FLX {
// This should be kept in sync with sai_model.p4
// In a perfect world this would be generated automatically from
// sai_model.p4
struct Parser_Model : public ::Model::Elem {
Parser_Model(Model::Type_Model headersType, Model::Type_Model userMetaType,
Model::Type_Model standardMetadataType) :
Model::Elem("ParserImpl"),
packetParam("packet", P4::P4CoreLibrary::instance.packetIn, 0),
headersParam("hdr", headersType, 1),
metadataParam("meta", userMetaType, 2),
standardMetadataParam("standard_metadata", standardMetadataType, 3)
{}
::Model::Param_Model packetParam;
::Model::Param_Model headersParam;
::Model::Param_Model metadataParam;
::Model::Param_Model standardMetadataParam;
};
struct Deparser_Model : public ::Model::Elem {
explicit Deparser_Model(Model::Type_Model headersType) :
Model::Elem("DeparserImpl"),
packetParam("packet", P4::P4CoreLibrary::instance.packetOut, 0),
headersParam("hdr", headersType, 1)
{}
::Model::Param_Model packetParam;
::Model::Param_Model headersParam;
};
// Models ingress and egress
struct Control_Model : public ::Model::Elem {
Control_Model(cstring name, Model::Type_Model headersType, Model::Type_Model metadataType,
Model::Type_Model standardMetadataType) :
Model::Elem(name),
headersParam("hdr", headersType, 0),
metadataParam("meta", metadataType, 1),
standardMetadataParam("standard_metadata", standardMetadataType, 2) {}
::Model::Param_Model headersParam;
::Model::Param_Model metadataParam;
::Model::Param_Model standardMetadataParam;
};
struct VerifyUpdate_Model : public ::Model::Elem {
VerifyUpdate_Model(cstring name, Model::Type_Model headersType) :
Model::Elem(name),
headersParam("hdr", headersType, 0) {}
::Model::Param_Model headersParam;
};
struct CounterType_Model : public ::Model::Enum_Model {
CounterType_Model() : ::Model::Enum_Model("CounterType"),
packets("packets"), bytes("bytes"), both("packets_and_bytes") {}
::Model::Elem packets;
::Model::Elem bytes;
::Model::Elem both;
};
struct MeterType_Model : public ::Model::Enum_Model {
MeterType_Model() : ::Model::Enum_Model("MeterType"),
packets("packets"), bytes("bytes") {}
::Model::Elem packets;
::Model::Elem bytes;
};
struct Checksum16_Model : public ::Model::Extern_Model {
Checksum16_Model() : Extern_Model("Checksum16"), get("get"),
resultType(IR::Type_Bits::get(32)) {}
::Model::Elem get;
const IR::Type* resultType;
};
struct ActionProfile_Model : public ::Model::Extern_Model {
ActionProfile_Model() : Extern_Model("action_profile"),
sizeType(IR::Type_Bits::get(32)), sizeParam("size") {}
const IR::Type* sizeType;
::Model::Elem sizeParam;
};
struct ActionSelector_Model : public ::Model::Extern_Model {
ActionSelector_Model() : Extern_Model("action_selector"),
sizeType(IR::Type_Bits::get(32)), sizeParam("size"),
widthType(IR::Type_Bits::get(32)),
algorithmParam("algorithm") {}
const IR::Type* sizeType;
::Model::Elem sizeParam;
const IR::Type* widthType;
::Model::Elem algorithmParam;
};
struct Random_Model : public ::Model::Elem {
Random_Model() : Elem("random"),
resultType(IR::Type_Bits::get(32)),
modify_field_rng_uniform("modify_field_rng_uniform") {}
const IR::Type* resultType;
::Model::Elem modify_field_rng_uniform;
};
class Truncate : public Model::Extern_Model {
public:
Truncate() : Extern_Model("truncate"), length_type(IR::Type::Bits::get(32)) {}
const IR::Type* length_type;
};
struct CounterOrMeter_Model : public ::Model::Extern_Model {
explicit CounterOrMeter_Model(cstring name) : Extern_Model(name),
sizeParam("size"), typeParam("type"),
size_type(IR::Type_Bits::get(32)),
index_type(IR::Type_Bits::get(32)), counterType() {}
::Model::Elem sizeParam;
::Model::Elem typeParam;
const IR::Type* size_type;
const IR::Type* index_type;
CounterType_Model counterType;
MeterType_Model meterType;
};
struct Register_Model : public ::Model::Extern_Model {
Register_Model() : Extern_Model("register"),
sizeParam("size"), read("read"), write("write"),
size_type(IR::Type_Bits::get(32)),
index_type(IR::Type_Bits::get(32)) {}
::Model::Elem sizeParam;
::Model::Elem read;
::Model::Elem write;
const IR::Type* size_type;
const IR::Type* index_type;
};
struct DigestReceiver_Model : public ::Model::Elem {
DigestReceiver_Model() : Elem("digest"), receiverType(IR::Type_Bits::get(32)) {}
const IR::Type* receiverType;
};
struct Counter_Model : public CounterOrMeter_Model {
Counter_Model() : CounterOrMeter_Model("counter"), increment("count") {}
::Model::Elem increment;
};
struct Meter_Model : public CounterOrMeter_Model {
Meter_Model() : CounterOrMeter_Model("meter"), executeMeter("execute_meter") {}
::Model::Elem executeMeter;
};
struct DirectMeter_Model : public CounterOrMeter_Model {
DirectMeter_Model() : CounterOrMeter_Model("direct_meter"), read("read") {}
::Model::Elem read;
};
struct DirectCounter_Model : public CounterOrMeter_Model {
DirectCounter_Model() : CounterOrMeter_Model("direct_counter"), count("count") {}
::Model::Elem count;
};
struct StandardMetadataType_Model : public ::Model::Type_Model {
explicit StandardMetadataType_Model(cstring name) :
::Model::Type_Model(name), dropBit("drop"), recirculate("recirculate_port"),
egress_spec("egress_spec") {}
::Model::Elem dropBit;
::Model::Elem recirculate;
::Model::Elem egress_spec;
};
struct CloneType_Model : public ::Model::Enum_Model {
CloneType_Model() : ::Model::Enum_Model("CloneType"),
i2e("I2E"), e2e("E2E") {}
::Model::Elem i2e;
::Model::Elem e2e;
};
struct Algorithm_Model : public ::Model::Enum_Model {
Algorithm_Model() : ::Model::Enum_Model("HashAlgorithm"),
crc32("crc32"), crc32_custom("crc32_custom"),
crc16("crc16"), crc16_custom("crc16_custom"),
random("random"), identity("identity") {}
::Model::Elem crc32;
::Model::Elem crc32_custom;
::Model::Elem crc16;
::Model::Elem crc16_custom;
::Model::Elem random;
::Model::Elem identity;
};
struct Hash_Model : public ::Model::Elem {
Hash_Model() : ::Model::Elem("hash") {}
};
struct Cloner_Model : public ::Model::Extern_Model {
Cloner_Model() : Extern_Model("clone"), clone3("clone3"), cloneType(),
sessionType(IR::Type_Bits::get(32)) {}
::Model::Elem clone3;
CloneType_Model cloneType;
const IR::Type* sessionType;
};
struct Switch_Model : public ::Model::Elem {
Switch_Model() : Model::Elem("SaiSwitch"),
parser("p"), verify("vr"),
ingress("ig"), egress("eg"),
ingress_bridge("ibridge"), egress_bridge("ebridge"),
ingress_router("irouter"),egress_router("erouter"),
update("ck"), deparser("dep") {}
::Model::Elem parser;
::Model::Elem verify;
::Model::Elem ingress;
::Model::Elem egress;
::Model::Elem ingress_bridge;
::Model::Elem egress_bridge;
::Model::Elem ingress_router;
::Model::Elem egress_router;
::Model::Elem update;
::Model::Elem deparser;
};
struct TableAttributes_Model {
TableAttributes_Model() : tableImplementation("implementation"),
counters("counters"),
meters("meters"), size("size"),
supportTimeout("support_timeout") {}
::Model::Elem tableImplementation;
::Model::Elem counters;
::Model::Elem meters;
::Model::Elem size;
::Model::Elem supportTimeout;
const unsigned defaultTableSize = 1024;
};
class V1Model : public ::Model::Model {
protected:
V1Model() :
Model::Model("0.1"), file("sai_model.p4"),
standardMetadata("standard_metadata"),
headersType("headers"),
metadataType("metadata"),
standardMetadataType("standard_metadata_t"),
parser(headersType, metadataType, standardMetadataType), deparser(headersType),
ingress("ingress", headersType, metadataType, standardMetadataType),
egress("egress", headersType, metadataType, standardMetadataType),
ingress_bridge("ingress_bridge", headersType, metadataType, standardMetadataType),
egress_bridge("egress_bridge", headersType, metadataType, standardMetadataType),
ingress_router("ingress_router", headersType, metadataType, standardMetadataType),
egress_router("egress_router", headersType, metadataType, standardMetadataType),
sw(), counterOrMeter("$"), counter(), meter(), random(), action_profile(),
action_selector(), clone(), resubmit("resubmit"),
tableAttributes(), rangeMatchType("range"), selectorMatchType("selector"),
verify("verifyChecksum", headersType), update("computeChecksum", headersType),
ck16(), digest_receiver(), hash(), algorithm(),
registers(), drop("mark_to_drop"),
recirculate("recirculate"), directMeter(), directCounter()
{}
public:
::Model::Elem file;
::Model::Elem standardMetadata;
::Model::Type_Model headersType;
::Model::Type_Model metadataType;
StandardMetadataType_Model standardMetadataType;
Parser_Model parser;
Deparser_Model deparser;
Control_Model ingress;
Control_Model egress;
Control_Model ingress_bridge;
Control_Model egress_bridge;
Control_Model ingress_router;
Control_Model egress_router;
Switch_Model sw;
Truncate truncate;
CounterOrMeter_Model counterOrMeter;
Counter_Model counter;
Meter_Model meter;
Random_Model random;
ActionProfile_Model action_profile;
ActionSelector_Model action_selector;
Cloner_Model clone;
::Model::Elem resubmit;
TableAttributes_Model tableAttributes;
::Model::Elem rangeMatchType;
::Model::Elem selectorMatchType;
VerifyUpdate_Model verify;
VerifyUpdate_Model update;
Checksum16_Model ck16;
DigestReceiver_Model digest_receiver;
Hash_Model hash;
Algorithm_Model algorithm;
Register_Model registers;
::Model::Elem drop;
::Model::Elem recirculate;
DirectMeter_Model directMeter;
DirectCounter_Model directCounter;
static V1Model instance;
};
} // namespace P4FLX
#endif /* _FRONTEND_SAI_MODEL_H_ */