P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfModel.h
1
/*
2
Copyright 2013-present Barefoot Networks, Inc.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations 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
25
namespace
EBPF {
26
27
struct
TableImpl_Model
:
public
::Model::Extern_Model
{
28
explicit
TableImpl_Model
(
cstring
name) : Extern_Model(name), size(
"size"
) {}
29
::Model::Elem
size;
30
};
31
32
struct
CounterArray_Model
:
public
::Model::Extern_Model
{
33
CounterArray_Model
()
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
45
enum
ModelArchitecture {
46
EbpfFilter,
47
XdpSwitch,
48
};
49
50
struct
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
57
struct
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
64
class
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;
88
::Model::Param_Model
packet;
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_ */
EBPF::EBPFModel
Definition
ebpfModel.h:64
Model::Model
Definition
model.h:64
cstring
Definition
cstring.h:72
EBPF::CounterArray_Model
Definition
ebpfModel.h:32
EBPF::Filter_Model
Definition
ebpfModel.h:57
EBPF::TableImpl_Model
Definition
ebpfModel.h:27
EBPF::Xdp_Model
Definition
ebpfModel.h:50
Model::Elem
Definition
model.h:28
Model::Extern_Model
Extern_Model : Type_Model.
Definition
model.h:52
Model::Param_Model
Param_Model : Elem.
Definition
model.h:57
backends
ebpf
ebpfModel.h
Generated on Tue Mar 26 2024 for