P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfPsaMeter.h
1/*
2Copyright 2022-present Orange
3Copyright 2022-present Open Networking Foundation
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 http://www.apache.org/licenses/LICENSE-2.0
8Unless required by applicable law or agreed to in writing, software
9distributed under the License is distributed on an "AS IS" BASIS,
10WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11See the License for the specific language governing permissions and
12limitations under the License.
13*/
14#ifndef BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAMETER_H_
15#define BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAMETER_H_
16
17#include "backends/ebpf/ebpfTable.h"
18
19namespace P4::EBPF {
20
21class ControlBodyTranslatorPSA;
22
24 private:
25 static IR::IndexedVector<IR::StructField> getValueFields();
26 static IR::Type_Struct *createSpinlockStruct();
27 static EBPFType *getBaseValueType(P4::ReferenceMap *refMap);
28 EBPFType *getIndirectValueType() const;
29 static cstring getBaseStructName(P4::ReferenceMap *refMap);
30 cstring getIndirectStructName() const;
31
32 void emitIndex(CodeBuilder *builder, const P4::ExternMethod *method,
33 ControlBodyTranslatorPSA *translator) const;
34
35 protected:
36 const cstring indirectValueField = "value"_cs;
37 const cstring spinlockField = "lock"_cs;
38
39 size_t size{};
40 EBPFType *keyType{};
41 bool isDirect;
42
43 public:
44 enum MeterType { PACKETS, BYTES };
45 MeterType type;
46
47 EBPFMeterPSA(const EBPFProgram *program, cstring instanceName,
48 const IR::Declaration_Instance *di, CodeGenInspector *codeGen);
49
50 static MeterType toType(const int typeCode);
51
52 void emitKeyType(CodeBuilder *builder) const;
53 static void emitValueStruct(CodeBuilder *builder, P4::ReferenceMap *refMap);
54 void emitValueType(CodeBuilder *builder) const;
55 void emitSpinLockField(CodeBuilder *builder) const;
56 void emitInstance(CodeBuilder *builder) const;
57 void emitExecute(CodeBuilder *builder, const P4::ExternMethod *method,
58 ControlBodyTranslatorPSA *translator) const;
59 void emitDirectExecute(CodeBuilder *builder, const P4::ExternMethod *method,
60 cstring valuePtr) const;
61
62 static cstring meterExecuteFunc(bool trace, P4::ReferenceMap *refMap);
63};
64
65} // namespace P4::EBPF
66
67#endif // BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAMETER_H_
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Definition ebpfPsaControl.h:30
Definition ebpfPsaMeter.h:23
Definition ebpfProgram.h:39
Also used to represent counters.
Definition ebpfTable.h:49
Base class for EBPF types.
Definition ebpfType.h:29
Definition methodInstance.h:168
Definition node.h:52
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition cstring.h:85
Definition codeGen.cpp:25