P4C
The P4 Compiler
Loading...
Searching...
No Matches
backends/tc/options.h
1/*
2 * Copyright (C) 2023 Intel Corporation
3 * SPDX-FileCopyrightText: 2023 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef BACKENDS_TC_OPTIONS_H_
9#define BACKENDS_TC_OPTIONS_H_
10
11#include <cstdlib>
12#include <limits>
13
14#include "backends/ebpf/ebpfOptions.h"
15#include "frontends/common/options.h"
16#include "lib/error.h"
17
18namespace P4::TC {
19
20class TCOptions : public CompilerOptions {
21 public:
22 // file to output to
23 std::filesystem::path outputFolder;
24 bool DebugOn = false;
25 // tracing eBPF code execution
26 bool emitTraceMessages = false;
27 // XDP2TC mode for PSA-eBPF
28 enum XDP2TC xdp2tcMode = XDP2TC_META;
29 unsigned timerProfiles = 4;
30
31 TCOptions() {
32 registerOption(
33 "-o", "output Directory",
34 [this](const char *arg) {
35 outputFolder = arg;
36 return true;
37 },
38 "Write pipeline template, introspection json and C output to given directory");
39 registerOption(
40 "-g", nullptr,
41 [this](const char *) {
42 DebugOn = true;
43 return true;
44 },
45 "Generates debug information");
46 registerOption(
47 "--trace", nullptr,
48 [this](const char *) {
49 emitTraceMessages = true;
50 return true;
51 },
52 "Generate tracing messages of packet processing");
53 registerOption(
54 "--xdp2tc", "MODE",
55 [this](const char *arg) {
56 if (!strcmp(arg, "meta")) {
57 xdp2tcMode = XDP2TC_META;
58 } else if (!strcmp(arg, "head")) {
59 xdp2tcMode = XDP2TC_HEAD;
60 } else if (!strcmp(arg, "cpumap")) {
61 xdp2tcMode = XDP2TC_CPUMAP;
62 } else {
63 ::P4::error(ErrorType::ERR_INVALID,
64 "Unknown --xdp2tc mode '%1%'; expected one of: meta, head, "
65 "cpumap",
66 arg);
67 return false;
68 }
69 return true;
70 },
71 "Select the mode used to pass metadata from XDP to TC "
72 "(possible values: meta, head, cpumap).");
73 registerOption(
74 "--num-timer-profiles", "profiles",
75 [this](const char *arg) {
76 char *end = nullptr;
77 long value = strtol(arg, &end, 0);
78 if (*end != 0 || value <= 0 ||
79 static_cast<unsigned long>(value) >
80 static_cast<unsigned long>(std::numeric_limits<unsigned>::max())) {
81 ::P4::error(ErrorType::ERR_INVALID,
82 "--num-timer-profiles expects a positive integer, got '%1%'", arg);
83 return false;
84 }
85 timerProfiles = static_cast<unsigned>(value);
86 return true;
87 },
88 "Defines the number of timer profiles. Default is 4.");
89 }
90};
91
92using TCContext = P4CContextWithOptions<TCOptions>;
93
94} // namespace P4::TC
95
96#endif /* BACKENDS_TC_OPTIONS_H_ */
Definition parser_options.h:174
This file defines functions for the pass to generate the introspection file.
Definition tc/backend.cpp:17
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:48