P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfModel.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 BACKENDS_EBPF_EBPFMODEL_H_
18#define BACKENDS_EBPF_EBPFMODEL_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::EBPF {
26
27using namespace P4::literals;
28
30 explicit TableImpl_Model(cstring name) : Extern_Model(name), size("size"_cs) {}
32};
33
36 : Extern_Model("CounterArray"_cs),
37 increment("increment"_cs),
38 add("add"_cs),
39 max_index("max_index"_cs),
40 sparse("sparse"_cs) {}
41 ::P4::Model::Elem increment;
43 ::P4::Model::Elem max_index;
44 ::P4::Model::Elem sparse;
45};
46
47enum ModelArchitecture {
48 EbpfFilter,
49 XdpSwitch,
50};
51
53 Xdp_Model() : Elem("xdp"_cs), parser("p"_cs), switch_("s"_cs), deparser("d"_cs) {}
54 ::P4::Model::Elem parser;
55 ::P4::Model::Elem switch_;
56 ::P4::Model::Elem deparser;
57};
58
60 Filter_Model() : Elem("ebpf_filter"_cs), parser("prs"_cs), filter("filt"_cs) {}
61 ::P4::Model::Elem parser;
62 ::P4::Model::Elem filter;
63};
64
67 protected:
68 EBPFModel()
69 : counterArray(),
70 array_table("array_table"_cs),
71 hash_table("hash_table"_cs),
72 tableImplProperty("implementation"_cs),
73 CPacketName("skb"_cs),
74 packet("packet"_cs, P4::P4CoreLibrary::instance().packetIn, 0),
75 arch(EbpfFilter),
76 filter(),
77 xdp(),
78 counterIndexType("u32"_cs),
79 counterValueType("u32"_cs) {}
80
81 public:
82 static EBPFModel instance;
83 static cstring reservedPrefix;
84
85 CounterArray_Model counterArray;
86 TableImpl_Model array_table;
87 TableImpl_Model hash_table;
88 ::P4::Model::Elem tableImplProperty;
89 ::P4::Model::Elem CPacketName;
91 ModelArchitecture arch;
94 Xdp_Model xdp;
95
96 cstring counterIndexType;
97 cstring counterValueType;
98
99 static cstring reserved(cstring name) { return reservedPrefix + name; }
100};
101
102} // namespace P4::EBPF
103
104#endif /* BACKENDS_EBPF_EBPFMODEL_H_ */
Keep this in sync with ebpf_model.p4 and xdp_model.p4.
Definition ebpfModel.h:66
Filter_Model filter
Only one of these should be used, depending on arch value.
Definition ebpfModel.h:93
Definition frontends/common/model.h:64
Definition cstring.h:85
Definition codeGen.cpp:25
Definition cstring.h:80
Definition ebpfModel.h:34
Definition ebpfModel.h:59
Definition ebpfModel.h:29
Definition ebpfModel.h:52
Definition frontends/common/model.h:28
Extern_Model : Type_Model.
Definition frontends/common/model.h:52
Param_Model : Elem.
Definition frontends/common/model.h:57