P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfPsaMeter.h
1
/*
2
Copyright 2022-present Orange
3
Copyright 2022-present Open Networking Foundation
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
http://www.apache.org/licenses/LICENSE-2.0
8
Unless required by applicable law or agreed to in writing, software
9
distributed under the License is distributed on an "AS IS" BASIS,
10
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
See the License for the specific language governing permissions and
12
limitations 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
19
namespace
P4::EBPF
{
20
21
class
ControlBodyTranslatorPSA;
22
23
class
EBPFMeterPSA
:
public
EBPFTableBase
{
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_
P4::EBPF::CodeBuilder
Definition
ebpf/codeGen.h:33
P4::EBPF::CodeGenInspector
Definition
ebpf/codeGen.h:41
P4::EBPF::ControlBodyTranslatorPSA
Definition
ebpfPsaControl.h:30
P4::EBPF::EBPFMeterPSA
Definition
ebpfPsaMeter.h:23
P4::EBPF::EBPFProgram
Definition
ebpfProgram.h:39
P4::EBPF::EBPFTableBase
Also used to represent counters.
Definition
ebpfTable.h:49
P4::EBPF::EBPFType
Base class for EBPF types.
Definition
ebpfType.h:29
P4::ExternMethod
Definition
methodInstance.h:168
P4::IR::IndexedVector
Definition
node.h:52
P4::ReferenceMap
Class used to encode maps from paths to declarations.
Definition
referenceMap.h:66
P4::cstring
Definition
cstring.h:85
P4::EBPF
Definition
codeGen.cpp:25
backends
ebpf
psa
externs
ebpfPsaMeter.h
Generated by
1.12.0