P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfPsaControl.h
1/*
2Copyright 2022-present Orange
3Copyright 2022-present Open Networking Foundation
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17#ifndef BACKENDS_EBPF_PSA_EBPFPSACONTROL_H_
18#define BACKENDS_EBPF_PSA_EBPFPSACONTROL_H_
19
20#include "backends/ebpf/ebpfControl.h"
21#include "backends/ebpf/psa/externs/ebpfPsaChecksum.h"
22#include "backends/ebpf/psa/externs/ebpfPsaRandom.h"
23#include "backends/ebpf/psa/externs/ebpfPsaRegister.h"
24#include "ebpfPsaTable.h"
25
26namespace P4::EBPF {
27
28class EBPFControlPSA;
29
31 public:
32 explicit ControlBodyTranslatorPSA(const EBPFControlPSA *control);
33
34 bool preorder(const IR::AssignmentStatement *a) override;
35
36 void processMethod(const P4::ExternMethod *method) override;
37
38 virtual cstring getParamName(const IR::PathExpression *);
39};
40
43 protected:
44 const EBPFTablePSA *table;
45
46 public:
47 ActionTranslationVisitorPSA(const EBPFProgram *program, cstring valueName,
48 const EBPFTablePSA *table);
49
50 bool preorder(const IR::PathExpression *pe) override;
51 bool isActionParameter(const IR::Expression *expression) const;
52
53 void processMethod(const P4::ExternMethod *method) override;
54 cstring getParamInstanceName(const IR::Expression *expression) const override;
55 cstring getParamName(const IR::PathExpression *) override;
56};
57
59 public:
61 bool timestampIsUsed = false;
62
63 const IR::Parameter *user_metadata;
64 const IR::Parameter *inputStandardMetadata;
65 const IR::Parameter *outputStandardMetadata;
66
67 std::map<cstring, EBPFHashPSA *> hashes;
68 std::map<cstring, EBPFRandomPSA *> randoms;
69 std::map<cstring, EBPFRegisterPSA *> registers;
70 std::map<cstring, EBPFMeterPSA *> meters;
71
72 EBPFControlPSA(const EBPFProgram *program, const IR::ControlBlock *control,
73 const IR::Parameter *parserHeaders)
74 : EBPFControl(program, control, parserHeaders) {}
75
76 void emit(CodeBuilder *builder) override;
77 void emitTableTypes(CodeBuilder *builder) override;
78 void emitTableInstances(CodeBuilder *builder) override;
79 void emitTableInitializers(CodeBuilder *builder) override;
80
81 EBPFRandomPSA *getRandomExt(cstring name) const {
82 auto result = ::P4::get(randoms, name);
83 BUG_CHECK(result != nullptr, "No random generator named %1%", name);
84 return result;
85 }
86
87 EBPFRegisterPSA *getRegister(cstring name) const {
88 auto result = ::P4::get(registers, name);
89 BUG_CHECK(result != nullptr, "No register named %1%", name);
90 return result;
91 }
92
93 EBPFHashPSA *getHash(cstring name) const {
94 auto result = ::P4::get(hashes, name);
95 BUG_CHECK(result != nullptr, "No hash named %1%", name);
96 return result;
97 }
98
99 EBPFMeterPSA *getMeter(cstring name) const {
100 auto result = ::P4::get(meters, name);
101 BUG_CHECK(result != nullptr, "No meter named %1%", name);
102 return result;
103 }
104
105 DECLARE_TYPEINFO(EBPFControlPSA, EBPFControl);
106};
107
108} // namespace P4::EBPF
109
110#endif /* BACKENDS_EBPF_PSA_EBPFPSACONTROL_H_ */
Definition ebpfTable.h:26
Definition ebpfPsaControl.h:42
Definition ebpf/codeGen.h:33
Definition ebpfControl.h:28
Definition ebpfPsaControl.h:30
Definition ebpfControl.h:57
Definition ebpfPsaControl.h:58
bool timestampIsUsed
Keeps track if ingress_timestamp or egress_timestamp is used within a control block.
Definition ebpfPsaControl.h:61
Definition ebpfProgram.h:39
Definition ebpfPsaRandom.h:22
Definition ebpfPsaTable.h:29
Definition methodInstance.h:168
Definition cstring.h:85
Definition codeGen.cpp:25