17#ifndef BACKENDS_EBPF_PSA_EBPFPIPELINE_H_
18#define BACKENDS_EBPF_PSA_EBPFPIPELINE_H_
20#include "backends/ebpf/ebpfProgram.h"
21#include "backends/ebpf/target.h"
22#include "ebpfPsaControl.h"
23#include "ebpfPsaDeparser.h"
58 :
EBPFProgram(options, nullptr, refMap, typeMap, nullptr),
64 functionName =
name.replace(
'-',
'_') +
"_func";
65 errorEnum =
"ParserError_t"_cs;
66 packetStartVar =
"pkt"_cs;
67 headerStartVar =
"hdr_start"_cs;
69 lengthVar =
"pkt_len"_cs;
70 endLabel =
"deparser"_cs;
77 oneKey = EBPFModel::reserved(
"one"_cs);
86 virtual cstring dropReturnCode() {
92 return "TC_ACT_SHOT"_cs;
94 virtual cstring forwardReturnCode() {
100 return "TC_ACT_OK"_cs;
103 virtual void emit(CodeBuilder *builder) = 0;
104 virtual void emitTrafficManager(CodeBuilder *builder) = 0;
105 virtual void emitPSAControlInputMetadata(CodeBuilder *builder) = 0;
106 virtual void emitPSAControlOutputMetadata(CodeBuilder *builder) = 0;
122 virtual void emitCPUMAPInitializers(CodeBuilder *builder);
123 virtual void emitCPUMAPLookup(CodeBuilder *builder);
128 virtual void emitPacketLength(CodeBuilder *builder);
129 virtual void emitTimestamp(CodeBuilder *builder);
130 void emitInputPortMapping(CodeBuilder *builder);
132 void emitHeadersFromCPUMAP(CodeBuilder *builder);
133 void emitMetadataFromCPUMAP(CodeBuilder *builder);
135 bool hasAnyMeter()
const {
136 auto directMeter = std::find_if(control->tables.begin(), control->tables.end(),
137 [](std::pair<const cstring, EBPFTable *> elem) {
138 return !elem.second->to<EBPFTablePSA>()->meters.empty();
140 bool anyDirectMeter = directMeter != control->tables.end();
141 return anyDirectMeter || (!control->meters.empty());
157 unsigned int maxResubmitDepth;
166 maxResubmitDepth = 4;
172 void emitSharedMetadataInitializer(
CodeBuilder *builder);
175 void emitPSAControlInputMetadata(
CodeBuilder *builder)
override;
176 void emitPSAControlOutputMetadata(
CodeBuilder *builder)
override;
190 void emitPSAControlInputMetadata(
CodeBuilder *builder)
override;
191 void emitPSAControlOutputMetadata(
CodeBuilder *builder)
override;
192 void emitCPUMAPLookup(
CodeBuilder *builder)
override;
194 virtual void emitCheckPacketMarkMetadata(
CodeBuilder *builder) = 0;
209 void emitTCWorkaroundUsingMeta(
CodeBuilder *builder);
210 void emitTCWorkaroundUsingHead(
CodeBuilder *builder);
211 void emitTCWorkaroundUsingCPUMAP(
CodeBuilder *builder);
222 void emitTrafficManager(
CodeBuilder *builder)
override;
223 void emitCheckPacketMarkMetadata(
CodeBuilder *builder)
override;
240 void emitTrafficManager(
CodeBuilder *builder)
override;
254 pktInstanceVar =
"0"_cs;
260 void emitTrafficManager(
CodeBuilder *builder)
override;
261 void emitCheckPacketMarkMetadata(
CodeBuilder *builder)
override;
276 void emitReadXDP2TCMetadataFromHead(
CodeBuilder *builder);
277 void emitReadXDP2TCMetadataFromCPUMAP(
CodeBuilder *builder);
Definition ebpf/codeGen.h:33
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 ebpfPsaDeparser.h:39
Definition ebpfPipeline.h:183
Definition ebpfPipeline.h:155
int actUnspecCode
Definition ebpfPipeline.h:160
EBPFPipeline represents a single eBPF program in the TC/XDP hook.
Definition ebpfPipeline.h:28
void emitLocalHeaderInstancesAsPointers(CodeBuilder *builder)
Generates a pointer to struct Headers_t and puts it on the BPF program's stack.
Definition ebpfPipeline.cpp:105
cstring name
A custom name of eBPF program.
Definition ebpfPipeline.h:31
void emitHeaderInstances(CodeBuilder *builder) override
Definition ebpfPipeline.cpp:117
cstring packetPathVar
Variables storing global metadata (packet_path & instance).
Definition ebpfPipeline.h:43
cstring inputPortVar
A variable to store ifindex after mapping (e.g. due to recirculation).
Definition ebpfPipeline.h:51
bool shouldEmitTimestamp() const
Definition ebpfPipeline.h:148
cstring ifindexVar
Variable storing ingress interface index.
Definition ebpfPipeline.h:39
cstring oneKey
A variable name storing "1" value. Used to access BPF array map index.
Definition ebpfPipeline.h:47
virtual void emitGlobalMetadataInitializer(CodeBuilder *builder)
Definition ebpfPipeline.cpp:153
void emitLocalVariables(CodeBuilder *builder) override
Generates a set of helper variables that are used during packet processing.
Definition ebpfPipeline.cpp:50
bool isEmpty() const
Definition ebpfPipeline.cpp:23
unsigned packetMark
A unique mark used to differentiate packets processed by P4/eBPF from others.
Definition ebpfPipeline.h:49
void emitCPUMAPHeadersInitializers(CodeBuilder *builder)
Generates a pointer to struct hdr_md. The pointer is used to access data from per-CPU map.
Definition ebpfPipeline.cpp:112
cstring sectionName
eBPF section name, which should a concatenation of classifier/ + a custom name.
Definition ebpfPipeline.h:33
cstring compilerGlobalMetadata
A name of an internal variable storing global metadata.
Definition ebpfPipeline.h:45
cstring timestampVar
Variable name storing current timestamp retrieved from bpf_ktime_get_ns().
Definition ebpfPipeline.h:37
cstring priorityVar
Variable storing skb->priority value (TC only).
Definition ebpfPipeline.h:41
void emitUserMetadataInstance(CodeBuilder *builder)
Definition ebpfPipeline.cpp:94
cstring contextVar
Variable name storing pointer to eBPF packet descriptor (e.g., __sk_buff).
Definition ebpfPipeline.h:35
Definition ebpfProgram.h:39
Definition ebpf/target.h:130
Definition ebpfPipeline.h:216
Definition ebpfPipeline.h:199
void emitTrafficManager(CodeBuilder *builder) override
Definition ebpfPipeline.cpp:556
void emitGlobalMetadataInitializer(CodeBuilder *builder) override
Definition ebpfPipeline.cpp:472
Definition ebpfPipeline.h:266
void emitGlobalMetadataInitializer(CodeBuilder *builder) override
Definition ebpfPipeline.cpp:750
Definition ebpfPipeline.h:245
void emitGlobalMetadataInitializer(CodeBuilder *builder) override
Definition ebpfPipeline.cpp:706
Definition ebpfPipeline.h:228
void emitGlobalMetadataInitializer(CodeBuilder *builder) override
Definition ebpfPipeline.cpp:682
Target XDP.
Definition ebpf/target.h:244
Definition ebpfOptions.h:26
bool emitTraceMessages
tracing eBPF code execution
Definition ebpfOptions.h:35
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition codeGen.cpp:25