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