P4C
The P4 Compiler
Loading...
Searching...
No Matches
dpdkContext.h
1/*
2Copyright 2021 Intel Corp.
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_DPDK_DPDKCONTEXT_H_
18#define BACKENDS_DPDK_DPDKCONTEXT_H_
19
20#include <regex>
21
22#include "constants.h"
23#include "control-plane/bfruntime.h"
24#include "dpdkProgramStructure.h"
25#include "lib/cstring.h"
26#include "lib/json.h"
27#include "lib/nullstream.h"
28#include "options.h"
29#include "p4/config/v1/p4info.pb.h"
30
31namespace p4configv1 = ::p4::config::v1;
32
37
38namespace P4::DPDK {
39
40using namespace P4::literals;
41
48 unsigned tableHandle;
53 bool is_add_on_miss;
54 bool idle_timeout_with_auto_delete;
55 bool isHidden;
56 unsigned size;
57 cstring controlName;
58 cstring externalName;
59 unsigned default_action_handle;
60 /* Non selector table keys from original P4 program */
61 std::vector<std::pair<cstring, cstring>> tableKeys;
62};
63
67 bool constant_default_action;
68 bool is_compiler_added_action;
69 bool allowed_as_hit_action;
70 bool allowed_as_default_action;
71 unsigned actionHandle;
72 cstring externalName;
74};
75
77 cstring externalName;
78 cstring externType;
79 cstring counterType;
80 unsigned table_id;
81};
82
85 std::string progName;
86 cstring buildDate;
87 cstring compileCommand;
88 cstring compilerVersion;
89 void initTopLevelCtxt(DpdkOptions &options) {
90 buildDate = options.getBuildDate();
91 compileCommand = options.getCompileCommand();
92 progName = options.file.stem();
93 compilerVersion = options.compilerVersion;
94 }
95};
96
99 unsigned max_n_groups;
100 unsigned max_n_members_per_group;
101 unsigned bound_to_action_data_table_handle;
102 void setAttributes(const IR::P4Table *tbl,
103 const std::map<const cstring, struct TableAttributes> &tableAttrmap) {
104 max_n_groups = 0;
105 max_n_members_per_group = 0;
106 auto n_groups = tbl->properties->getProperty("n_groups_max");
107 if (n_groups) {
108 auto n_groups_expr = n_groups->value->to<IR::ExpressionValue>()->expression;
109 max_n_groups = n_groups_expr->to<IR::Constant>()->asInt();
110 }
111 auto n_members = tbl->properties->getProperty("n_members_per_group_max");
112 if (n_members) {
113 auto n_members_expr = n_members->value->to<IR::ExpressionValue>()->expression;
114 max_n_members_per_group = n_members_expr->to<IR::Constant>()->asInt();
115 }
116 // Fetch associated member table handle
117 cstring actionDataTableName = tbl->name.originalName.replace("_sel", "");
118 auto actionTableAttr = ::P4::get(tableAttrmap, actionDataTableName);
119 bound_to_action_data_table_handle = actionTableAttr.tableHandle;
120 }
121};
122
125 P4::ReferenceMap *refmap;
126 DpdkProgramStructure *structure;
127 const p4configv1::P4Info &p4info;
128 DpdkOptions &options;
131 std::vector<const IR::Declaration_Instance *> externs;
132
134 std::map<const cstring, struct TableAttributes> tableAttrmap;
135 std::map<cstring, struct actionAttributes> actionAttrMap;
136 std::map<cstring, struct externAttributes> externAttrMap;
137
139 std::map<cstring, size_t> context_handle_map;
140
141 public:
143 const p4configv1::P4Info &p4info, DpdkOptions &options)
144 : refmap(refmap), structure(structure), p4info(p4info), options(options) {}
145
146 void serializeContextJson(std::ostream *destination);
147 const Util::JsonObject *genContextJsonObject();
148 void addMatchTables(Util::JsonArray *tablesJson);
149 size_t getHandleId(cstring name);
150 void collectHandleId();
151 void addExternInfo(Util::JsonArray *externsJson);
152 Util::JsonObject *initTableCommonJson(const cstring name, const struct TableAttributes &attr);
153 void addKeyField(Util::JsonArray *keyJson, const cstring name, const cstring annon,
154 const IR::KeyElement *key, int position);
155 Util::JsonArray *addActions(const IR::P4Table *table, const cstring ctrlName, bool isMatch);
156 bool addRefTables(const cstring tbl_name, const IR::P4Table **memberTable,
157 Util::JsonObject *tableJson);
158 void addImmediateField(Util::JsonArray *paramJson, const cstring name, int dest_start,
159 int dest_Width);
160 void addActionParam(Util::JsonArray *paramJson, const cstring name, int bitWidth, int position,
161 int byte_array_index);
162 Util::JsonObject *addMatchAttributes(const IR::P4Table *table, const cstring ctrlName);
163 void setActionAttributes(const IR::P4Table *table);
164 void setDefaultActionHandle(const IR::P4Table *table);
166 cstring removePipePrefix(cstring);
167};
168
169} // namespace P4::DPDK
170
171#endif /* BACKENDS_DPDK_DPDKCONTEXT_H_ */
This pass generates context JSON into user specified file.
Definition dpdkContext.h:124
void addActionParam(Util::JsonArray *paramJson, const cstring name, int bitWidth, int position, int byte_array_index)
This function adds a single parameter to the parameters array.
Definition dpdkContext.cpp:371
void addMatchTables(Util::JsonArray *tablesJson)
Add tables to the context json.
Definition dpdkContext.cpp:478
void addExternInfo(Util::JsonArray *externsJson)
Add extern information to the context json.
Definition dpdkContext.cpp:533
void setActionAttributes(const IR::P4Table *table)
This function sets action attributes for actions in a table.
Definition dpdkContext.cpp:237
void addKeyField(Util::JsonArray *keyJson, const cstring name, const cstring annon, const IR::KeyElement *key, int position)
This functions insert a single key field in the match keys array.
Definition dpdkContext.cpp:166
bool addRefTables(const cstring tbl_name, const IR::P4Table **memberTable, Util::JsonObject *tableJson)
This function adds the tables referred by this table.
Definition dpdkContext.cpp:433
Util::JsonArray * addActions(const IR::P4Table *table, const cstring ctrlName, bool isMatch)
This function creates JSON objects for actions within a table.
Definition dpdkContext.cpp:383
Util::JsonObject * initTableCommonJson(const cstring name, const struct TableAttributes &attr)
This function sets the common table properties.
Definition dpdkContext.cpp:192
void addImmediateField(Util::JsonArray *paramJson, const cstring name, int dest_start, int dest_Width)
This functions creates JSON object for immediate fields (action parameters).
Definition dpdkContext.cpp:320
void CollectTablesAndSetAttributes()
Definition dpdkContext.cpp:35
Util::JsonObject * addMatchAttributes(const IR::P4Table *table, const cstring ctrlName)
This functions creates JSON object for match attributes of a table.
Definition dpdkContext.cpp:330
Definition backends/dpdk/options.h:24
Definition node.h:52
Definition visitor.h:400
cstring compilerVersion
Compiler version.
Definition parser_options.h:85
std::filesystem::path file
file to compile (- for stdin)
Definition parser_options.h:81
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition json.h:115
Definition json.h:164
Definition cstring.h:85
Definition dpdk/backend.cpp:37
cstring tableType
Definition dpdkContext.h:52
unsigned tableHandle
Unique ID for the table.
Definition dpdkContext.h:48
cstring direction
Direction of the table, can be ["ingress","egress"].
Definition dpdkContext.h:46
Definition dpdkContext.h:44
Definition dpdkContext.h:66
Definition dpdkContext.h:76
Definition cstring.h:80
Selection table attributes.
Definition dpdkContext.h:98
Program level information for context json.
Definition dpdkContext.h:84
Collect information related to P4 programs targeting dpdk.
Definition dpdkProgramStructure.h:16