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