P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfPsaTableImplementation.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
18#ifndef BACKENDS_EBPF_PSA_EXTERNS_EBPFPSATABLEIMPLEMENTATION_H_
19#define BACKENDS_EBPF_PSA_EXTERNS_EBPFPSATABLEIMPLEMENTATION_H_
20
21#include "backends/ebpf/ebpfTable.h"
22#include "backends/ebpf/psa/ebpfPsaTable.h"
23#include "backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h"
24
25namespace P4::EBPF {
26
29 public:
31 const IR::Declaration_Instance *decl);
32
33 void emitTypes(CodeBuilder *builder) override;
34 void emitInitializer(CodeBuilder *builder) override;
35 virtual void emitReferenceEntry(CodeBuilder *builder);
36
37 virtual void registerTable(const EBPFTablePSA *instance);
38
39 virtual void applyImplementation(CodeBuilder *builder, cstring tableValueName,
40 cstring actionRunVariable) = 0;
41
42 protected:
43 const IR::Declaration_Instance *declaration;
44 cstring referenceName;
45
46 void verifyTableActionList(const EBPFTablePSA *instance);
47 void verifyTableNoDefaultAction(const EBPFTablePSA *instance);
48 void verifyTableNoDirectObjects(const EBPFTablePSA *instance);
49 void verifyTableNoEntries(const EBPFTablePSA *instance);
50
51 unsigned getUintFromExpression(const IR::Expression *expr, unsigned defaultValue);
52
54};
55
57 public:
58 EBPFActionProfilePSA(const EBPFProgram *program, CodeGenInspector *codeGen,
59 const IR::Declaration_Instance *decl);
60
61 void emitInstance(CodeBuilder *builder) override;
62 void applyImplementation(CodeBuilder *builder, cstring tableValueName,
63 cstring actionRunVariable) override;
64
66};
67
69 public:
70 EBPFActionSelectorPSA(const EBPFProgram *program, CodeGenInspector *codeGen,
71 const IR::Declaration_Instance *decl);
72
73 void emitInitializer(CodeBuilder *builder) override;
74 void emitInstance(CodeBuilder *builder) override;
75 void emitReferenceEntry(CodeBuilder *builder) override;
76
77 void applyImplementation(CodeBuilder *builder, cstring tableValueName,
78 cstring actionRunVariable) override;
79
80 void registerTable(const EBPFTablePSA *instance) override;
81
82 void emitCacheTypes(CodeBuilder *builder) override;
83 void emitCacheVariables(CodeBuilder *builder);
84 void emitCacheLookup(CodeBuilder *builder, cstring key, cstring value) override;
85 void emitCacheUpdate(CodeBuilder *builder, cstring key, cstring value) override;
86
87 protected:
88 typedef std::vector<const IR::KeyElement *> SelectorsListType;
89
90 const IR::Property *emptyGroupAction;
91 EBPFHashAlgorithmPSA *hashEngine;
92 SelectorsListType selectors;
93 cstring actionsMapName;
94 cstring groupsMapName;
95 cstring emptyGroupActionMapName;
96 size_t groupsMapSize;
97 cstring outputHashMask;
98 cstring isGroupEntryName;
99 cstring groupStateVarName;
100 cstring cacheKeyVar;
101 cstring cacheDoUpdateVar;
102
103 EBPFHashAlgorithmPSA::ArgumentsList unpackSelectors();
104 SelectorsListType getSelectorsFromTable(const EBPFTablePSA *instance);
105
106 void verifyTableSelectorKeySet(const EBPFTablePSA *instance);
107 void verifyTableEmptyGroupAction(const EBPFTablePSA *instance);
108
110};
111
112} // namespace P4::EBPF
113
114#endif // BACKENDS_EBPF_PSA_EXTERNS_EBPFPSATABLEIMPLEMENTATION_H_
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Definition ebpfPsaTableImplementation.h:56
Definition ebpfPsaTableImplementation.h:68
Definition ebpfPsaHashAlgorithm.h:26
Definition ebpfProgram.h:39
Base class for ActionProfile and ActionSelector.
Definition ebpfPsaTableImplementation.h:28
Definition ebpfPsaTable.h:29
Definition cstring.h:85
Definition codeGen.cpp:25