17#ifndef BACKENDS_EBPF_PSA_EBPFPSAGEN_H_
18#define BACKENDS_EBPF_PSA_EBPFPSAGEN_H_
20#include "backends/ebpf/codeGen.h"
21#include "backends/ebpf/ebpfObject.h"
22#include "backends/ebpf/ebpfOptions.h"
23#include "ebpfPipeline.h"
24#include "ebpfPsaParser.h"
25#include "xdpHelpProgram.h"
29enum pipeline_type { TC_INGRESS, TC_EGRESS, XDP_INGRESS, XDP_EGRESS, TC_TRAFFIC_MANAGER };
34 std::vector<EBPF::EBPFType *> ebpfTypes;
37 : options(options), ebpfTypes(ebpfTypes) {}
40 virtual void emitPreamble(
CodeBuilder *builder)
const = 0;
49 static constexpr unsigned MaxClones = 64;
50 static constexpr unsigned MaxCloneSessions = 1024;
63 void emitPreamble(
CodeBuilder *builder)
const override;
64 void emitCommonPreamble(
CodeBuilder *builder)
const override;
65 void emitInternalStructures(
CodeBuilder *pBuilder)
const override;
67 void emitGlobalHeadersMetadata(
CodeBuilder *builder)
const override;
68 void emitPacketReplicationTables(
CodeBuilder *builder)
const;
69 void emitPipelineInstances(
CodeBuilder *builder)
const override;
71 virtual void emitInitializerSection(
CodeBuilder *builder)
const = 0;
72 void emitHelperFunctions(
CodeBuilder *builder)
const;
76 void emitCRC32LookupTableInitializer(
CodeBuilder *builder)
const;
77 void emitCRC32LookupTableInstance(
CodeBuilder *builder)
const;
90 void emitInstances(
CodeBuilder *builder)
const override;
91 void emitInitializerSection(
CodeBuilder *builder)
const override;
100 static constexpr unsigned egressDevmapSize = 256;
111 void emitPreamble(
CodeBuilder *builder)
const override;
112 void emitInstances(
CodeBuilder *builder)
const override;
113 void emitInitializerSection(
CodeBuilder *builder)
const override;
115 void emitXDP2TCInternalStructures(
CodeBuilder *builder)
const;
127 : options(options), typemap(typemap), refmap(refmap), ebpf_psa_arch(
nullptr) {}
130 const IR::Node *preorder(IR::ToplevelBlock *p)
override;
137 const pipeline_type type;
139 const IR::ParserBlock *parserBlock;
140 const IR::ControlBlock *controlBlock;
141 const IR::ControlBlock *deparserBlock;
148 const IR::ParserBlock *parserBlock,
const IR::ControlBlock *controlBlock,
154 parserBlock(parserBlock),
155 controlBlock(controlBlock),
156 deparserBlock(deparserBlock),
161 bool preorder(
const IR::PackageBlock *block)
override;
174 : program(program), type(type), typemap(typemap), parser(
nullptr) {}
176 bool preorder(
const IR::ParserBlock *prsr)
override;
177 bool preorder(
const IR::P4ValueSet *pvs)
override;
186 const IR::Parameter *parserHeaders;
195 parserHeaders(parserHeaders),
198 bool preorder(
const IR::TableBlock *)
override;
199 bool preorder(
const IR::ControlBlock *)
override;
200 bool preorder(
const IR::Declaration_Variable *)
override;
201 bool preorder(
const IR::Member *m)
override;
202 bool preorder(
const IR::IfStatement *a)
override;
203 bool preorder(
const IR::ExternBlock *instance)
override;
210 pipeline_type pipelineType;
212 const IR::Parameter *parserHeaders;
213 const IR::Parameter *istd;
218 const IR::Parameter *istd, pipeline_type type)
221 parserHeaders(parserHeaders),
225 bool preorder(
const IR::ControlBlock *)
override;
226 bool preorder(
const IR::Declaration_Instance *)
override;
Definition ebpf/codeGen.h:33
Definition ebpfPsaGen.h:181
Definition ebpfPsaGen.h:208
Definition ebpfPsaGen.h:165
Definition ebpfPsaGen.h:119
Definition ebpfPsaGen.h:135
Definition ebpfPsaControl.h:58
Definition ebpfPsaDeparser.h:39
Definition ebpfParser.h:79
EBPFPipeline represents a single eBPF program in the TC/XDP hook.
Definition ebpfPipeline.h:28
Definition ebpfProgram.h:39
Definition ebpfPsaParser.h:40
Definition ebpfPsaGen.h:31
Definition ebpfPsaGen.h:80
Definition ebpfPsaGen.h:94
EBPFPipeline * tcIngressForXDP
TC Ingress program used to support packet cloning in the XDP mode.
Definition ebpfPsaGen.h:97
EBPFPipeline * tcEgressForXDP
If the XDP mode is used, we need to have TC Egress pipeline to handle cloned packets.
Definition ebpfPsaGen.h:99
Definition ebpfPsaGen.h:47
void emitCRC32LookupTableTypes(CodeBuilder *builder) const
TODO: move them to the externs/ebpfPsaHashAlgorithm.cpp file.
Definition ebpfPsaGen.cpp:322
void emitTypes(CodeBuilder *builder) const override
Generate headers and structs in p4 prog.
Definition ebpfPsaGen.cpp:117
Definition xdpHelpProgram.h:24
Definition ebpfOptions.h:26
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition codeGen.cpp:25