P4C
The P4 Compiler
Loading...
Searching...
No Matches
ebpfOptions.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef BACKENDS_EBPF_EBPFOPTIONS_H_
9#define BACKENDS_EBPF_EBPFOPTIONS_H_
10
11#include "frontends/common/options.h"
12
13namespace P4 {
14
15enum XDP2TC { XDP2TC_NONE, XDP2TC_META, XDP2TC_HEAD, XDP2TC_CPUMAP };
16
17class EbpfOptions : public CompilerOptions {
18 public:
20 std::filesystem::path outputFile;
22 bool loadIRFromJson = false;
24 bool emitExterns = false;
26 bool emitTraceMessages = false;
28 bool generateToXDP = false;
30 enum XDP2TC xdp2tcMode = XDP2TC_NONE;
32 unsigned int maxTernaryMasks = 128;
34 bool enableTableCache = false;
35
36 EbpfOptions();
37
38 void calculateXDP2TCMode() {
39 if (arch != "psa") {
40 return;
41 }
42
43 if (generateToXDP && xdp2tcMode == XDP2TC_META) {
44 std::cerr
45 << "XDP2TC 'meta' mode cannot be used if XDP is enabled. "
46 "Falling back to 'head' mode. For more information see "
47 "https://github.com/p4lang/p4c/blob/main/backends/ebpf/psa/README.md#xdp2tc-mode"
48 << std::endl;
49 xdp2tcMode = XDP2TC_HEAD;
50 } else if (generateToXDP && xdp2tcMode == XDP2TC_NONE) {
51 // use 'head' mode by default; it's the safest option.
52 std::cout << "Setting XDP2TC 'head' mode by default for XDP-based hook." << std::endl;
53 xdp2tcMode = XDP2TC_HEAD;
54 } else if (!generateToXDP && xdp2tcMode == XDP2TC_NONE) {
55 std::cout << "Setting XDP2TC 'meta' mode by default for TC-based hook." << std::endl;
56 // For TC, use 'meta' mode by default.
57 xdp2tcMode = XDP2TC_META;
58 }
59 BUG_CHECK(xdp2tcMode != XDP2TC_NONE, "xdp2tc mode should not be set to NONE, bug?");
60 }
61};
62
63using EbpfContext = P4CContextWithOptions<EbpfOptions>;
64
65} // namespace P4
66
67#endif /* BACKENDS_EBPF_EBPFOPTIONS_H_ */
bool generateToXDP
generate program to XDP layer
Definition ebpfOptions.h:28
bool loadIRFromJson
read from json
Definition ebpfOptions.h:22
unsigned int maxTernaryMasks
maximum number of unique ternary masks
Definition ebpfOptions.h:32
bool emitTraceMessages
tracing eBPF code execution
Definition ebpfOptions.h:26
bool emitExterns
Externs generation.
Definition ebpfOptions.h:24
bool enableTableCache
Enable table cache for LPM and ternary tables.
Definition ebpfOptions.h:34
std::filesystem::path outputFile
file to output to
Definition ebpfOptions.h:20
Definition parser_options.h:170
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13