8#ifndef BACKENDS_DPDK_DPDKCONTEXT_H_
9#define BACKENDS_DPDK_DPDKCONTEXT_H_
14#include "control-plane/bfruntime.h"
15#include "dpdkProgramStructure.h"
16#include "lib/cstring.h"
18#include "lib/nullstream.h"
20#include "p4/config/v1/p4info.pb.h"
22namespace p4configv1 = ::p4::config::v1;
31using namespace P4::literals;
45 bool idle_timeout_with_auto_delete;
50 unsigned default_action_handle;
52 std::vector<std::pair<cstring, cstring>> tableKeys;
58 bool constant_default_action;
59 bool is_compiler_added_action;
60 bool allowed_as_hit_action;
61 bool allowed_as_default_action;
62 unsigned actionHandle;
81 buildDate = options.getBuildDate();
82 compileCommand = options.getCompileCommand();
83 progName = options.file.stem();
84 compilerVersion = options.compilerVersion;
90 unsigned max_n_groups;
91 unsigned max_n_members_per_group;
92 unsigned bound_to_action_data_table_handle;
93 void setAttributes(
const IR::P4Table *tbl,
94 const std::map<const cstring, struct TableAttributes> &tableAttrmap) {
96 max_n_members_per_group = 0;
97 auto n_groups = tbl->properties->getProperty(
"n_groups_max");
99 auto n_groups_expr = n_groups->value->to<IR::ExpressionValue>()->expression;
100 max_n_groups = n_groups_expr->to<IR::Constant>()->asInt();
102 auto n_members = tbl->properties->getProperty(
"n_members_per_group_max");
104 auto n_members_expr = n_members->value->to<IR::ExpressionValue>()->expression;
105 max_n_members_per_group = n_members_expr->to<IR::Constant>()->asInt();
108 cstring actionDataTableName = tbl->name.originalName.replace(
"_sel",
"");
109 auto actionTableAttr = ::P4::get(tableAttrmap, actionDataTableName);
110 bound_to_action_data_table_handle = actionTableAttr.tableHandle;
115class DpdkContextGenerator :
public Inspector {
118 const p4configv1::P4Info &p4info;
122 std::vector<const IR::Declaration_Instance *> externs;
125 std::map<const cstring, struct TableAttributes> tableAttrmap;
126 std::map<cstring, struct actionAttributes> actionAttrMap;
127 std::map<cstring, struct externAttributes> externAttrMap;
130 std::map<cstring, size_t> context_handle_map;
134 const p4configv1::P4Info &p4info,
DpdkOptions &options)
135 : refmap(refmap), structure(structure), p4info(p4info), options(options) {}
137 void serializeContextJson(std::ostream *destination);
140 size_t getHandleId(
cstring name);
141 void collectHandleId();
145 const IR::KeyElement *key,
int position);
152 int byte_array_index);
155 void setDefaultActionHandle(
const IR::P4Table *table);
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:360
void addMatchTables(Util::JsonArray *tablesJson)
Add tables to the context json.
Definition dpdkContext.cpp:467
void addExternInfo(Util::JsonArray *externsJson)
Add extern information to the context json.
Definition dpdkContext.cpp:522
void setActionAttributes(const IR::P4Table *table)
This function sets action attributes for actions in a table.
Definition dpdkContext.cpp:226
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:155
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:422
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:372
Util::JsonObject * initTableCommonJson(const cstring name, const struct TableAttributes &attr)
This function sets the common table properties.
Definition dpdkContext.cpp:181
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:309
void CollectTablesAndSetAttributes()
Definition dpdkContext.cpp:24
Util::JsonObject * addMatchAttributes(const IR::P4Table *table, const cstring ctrlName)
This functions creates JSON object for match attributes of a table.
Definition dpdkContext.cpp:319
Definition backends/dpdk/options.h:15
Definition indexed_vector.h:31
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
Definition lib/json.h:128
Definition lib/json.h:177
Definition dpdk/backend.cpp:26
cstring tableType
Definition dpdkContext.h:43
unsigned tableHandle
Unique ID for the table.
Definition dpdkContext.h:39
cstring direction
Direction of the table, can be ["ingress","egress"].
Definition dpdkContext.h:37
Definition dpdkContext.h:35
Definition dpdkContext.h:57
Definition dpdkContext.h:67
Selection table attributes.
Definition dpdkContext.h:89
Program level information for context json.
Definition dpdkContext.h:75
Collect information related to P4 programs targeting dpdk.
Definition dpdkProgramStructure.h:22