P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfPsaCounter.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_EXTERNS_EBPFPSACOUNTER_H_
18#define BACKENDS_EBPF_PSA_EXTERNS_EBPFPSACOUNTER_H_
19
20#include "backends/ebpf/ebpfTable.h"
21
22namespace P4::EBPF {
23
24class ControlBodyTranslatorPSA;
25
27 protected:
28 EBPFType *dataplaneWidthType;
29 EBPFType *indexWidthType;
30 bool isDirect;
31
32 public:
33 enum CounterType { PACKETS, BYTES, PACKETS_AND_BYTES };
34 CounterType type;
35
36 EBPFCounterPSA(const EBPFProgram *program, const IR::Declaration_Instance *di, cstring name,
37 CodeGenInspector *codeGen);
38
39 static CounterType toCounterType(int type);
40
41 void emitTypes(CodeBuilder *builder) override;
42 virtual void emitKeyType(CodeBuilder *builder);
43 virtual void emitValueType(CodeBuilder *builder);
44 void emitInstance(CodeBuilder *builder) override;
45
46 void emitMethodInvocation(CodeBuilder *builder, const P4::ExternMethod *method,
47 CodeGenInspector *codeGen);
48 void emitDirectMethodInvocation(CodeBuilder *builder, const P4::ExternMethod *method,
49 cstring valuePtr);
50 virtual void emitCount(CodeBuilder *builder, const IR::MethodCallExpression *expression,
51 CodeGenInspector *codeGen);
52 virtual void emitCounterUpdate(CodeBuilder *builder, cstring target, cstring keyName);
53 virtual void emitCounterInitializer(CodeBuilder *builder);
54
55 DECLARE_TYPEINFO(EBPFCounterPSA, EBPFCounterTable);
56};
57
58} // namespace P4::EBPF
59
60#endif /* BACKENDS_EBPF_PSA_EXTERNS_EBPFPSACOUNTER_H_ */
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Definition ebpfPsaCounter.h:26
Definition ebpfTable.h:150
Definition ebpfProgram.h:39
Base class for EBPF types.
Definition ebpfType.h:29
Definition methodInstance.h:168
Definition cstring.h:85
Definition codeGen.cpp:25