P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfOptions.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef BACKENDS_EBPF_EBPFOPTIONS_H_
18#define BACKENDS_EBPF_EBPFOPTIONS_H_
19
20#include "frontends/common/options.h"
21
22namespace P4 {
23
24enum XDP2TC { XDP2TC_NONE, XDP2TC_META, XDP2TC_HEAD, XDP2TC_CPUMAP };
25
27 public:
29 std::filesystem::path outputFile;
31 bool loadIRFromJson = false;
33 bool emitExterns = false;
35 bool emitTraceMessages = false;
37 bool generateToXDP = false;
39 enum XDP2TC xdp2tcMode = XDP2TC_NONE;
41 unsigned int maxTernaryMasks = 128;
43 bool enableTableCache = false;
44
46
47 void calculateXDP2TCMode() {
48 if (arch != "psa") {
49 return;
50 }
51
52 if (generateToXDP && xdp2tcMode == XDP2TC_META) {
53 std::cerr
54 << "XDP2TC 'meta' mode cannot be used if XDP is enabled. "
55 "Falling back to 'head' mode. For more information see "
56 "https://github.com/p4lang/p4c/blob/main/backends/ebpf/psa/README.md#xdp2tc-mode"
57 << std::endl;
58 xdp2tcMode = XDP2TC_HEAD;
59 } else if (generateToXDP && xdp2tcMode == XDP2TC_NONE) {
60 // use 'head' mode by default; it's the safest option.
61 std::cout << "Setting XDP2TC 'head' mode by default for XDP-based hook." << std::endl;
62 xdp2tcMode = XDP2TC_HEAD;
63 } else if (!generateToXDP && xdp2tcMode == XDP2TC_NONE) {
64 std::cout << "Setting XDP2TC 'meta' mode by default for TC-based hook." << std::endl;
65 // For TC, use 'meta' mode by default.
66 xdp2tcMode = XDP2TC_META;
67 }
68 BUG_CHECK(xdp2tcMode != XDP2TC_NONE, "xdp2tc mode should not be set to NONE, bug?");
69 }
70};
71
72using EbpfContext = P4CContextWithOptions<EbpfOptions>;
73
74} // namespace P4
75
76#endif /* BACKENDS_EBPF_EBPFOPTIONS_H_ */
Definition frontends/common/options.h:30
Definition ebpfOptions.h:26
bool generateToXDP
generate program to XDP layer
Definition ebpfOptions.h:37
bool loadIRFromJson
read from json
Definition ebpfOptions.h:31
unsigned int maxTernaryMasks
maximum number of unique ternary masks
Definition ebpfOptions.h:41
bool emitTraceMessages
tracing eBPF code execution
Definition ebpfOptions.h:35
bool emitExterns
Externs generation.
Definition ebpfOptions.h:33
bool enableTableCache
Enable table cache for LPM and ternary tables.
Definition ebpfOptions.h:43
std::filesystem::path outputFile
file to output to
Definition ebpfOptions.h:29
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24