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 <getopt.h>
21
22#include "frontends/common/options.h"
23
24enum XDP2TC { XDP2TC_NONE, XDP2TC_META, XDP2TC_HEAD, XDP2TC_CPUMAP };
25
27 public:
28 // file to output to
29 cstring outputFile = nullptr;
30 // read from json
31 bool loadIRFromJson = false;
32 // Externs generation
33 bool emitExterns = false;
34 // tracing eBPF code execution
35 bool emitTraceMessages = false;
36 // generate program to XDP layer
37 bool generateToXDP = false;
38 // XDP2TC mode for PSA-eBPF
39 enum XDP2TC xdp2tcMode = XDP2TC_NONE;
40 // maximum number of unique ternary masks
41 unsigned int maxTernaryMasks = 128;
42 // Enable table cache for LPM and ternary tables
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
73
74#endif /* BACKENDS_EBPF_EBPFOPTIONS_H_ */
Definition options.h:26
Definition ebpfOptions.h:26
Definition parser_options.h:167
Definition cstring.h:72