P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
bfruntime_ext.h
1/* Copyright 2021 Intel Corporation
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14*/
15
16#ifndef DPDK_CONTROL_PLANE_BFRUNTIME_EXT_H_
17#define DPDK_CONTROL_PLANE_BFRUNTIME_EXT_H_
18
19#include "backends/dpdk/constants.h"
20#include "backends/dpdk/options.h"
21#include "backends/dpdk/p4/config/p4info.pb.h"
22#include "control-plane/bfruntime.h"
23
24namespace P4 {
25
26namespace BFRT {
27
31 public:
32 BFRuntimeSchemaGenerator(const p4configv1::P4Info &p4info, bool isTDI,
33 DPDK::DpdkOptions &options)
34 : BFRuntimeGenerator(p4info), isTDI(isTDI), options(options) {}
35
37 const Util::JsonObject *genSchema() const override;
38
39 private:
40 bool isTDI;
41 DPDK::DpdkOptions &options;
42 // TODO(antonin): these values may need to be available to the BF-RT
43 // implementation as well, if they want to expose them as enums.
44
45 // To avoid potential clashes with P4 names, we prefix the names of "fixed"
46 // data field with a '$'. For example, for TD_DATA_ACTION_MEMBER_ID, we
47 // use the name $ACTION_MEMBER_ID.
48 enum BFRuntimeDataFieldIds : P4Id {
49 // ids for fixed data fields must not collide with the auto-generated
50 // ids for P4 fields (e.g. match key fields). Snapshot tables include
51 // ALL the fields defined in the P4 program so we need to ensure that
52 // this BF_RT_DATA_START offset is quite large.
53 // PSA Ids are between TD_DATA_START = (1 << 16) and TD_DATA_END,
54 BF_RT_DATA_START = TD_DATA_END,
55
56 BF_RT_DATA_ACTION_MEMBER_ID,
57 BF_RT_DATA_SELECTOR_GROUP_ID,
58 BF_RT_DATA_ACTION_MEMBER_STATUS,
59 BF_RT_DATA_MAX_GROUP_SIZE,
60 BF_RT_DATA_HASH_VALUE,
61 };
62 // Externs only for DPDK backend
63 struct ActionSelector;
64
65 void addDPDKExterns(Util::JsonArray *tablesJson, Util::JsonArray *learnFiltersJson) const;
66 void addActionSelectorCommon(Util::JsonArray *tablesJson,
67 const ActionSelector &actionProf) const;
68 void addActionSelectorGetMemberCommon(Util::JsonArray *tablesJson,
69 const ActionSelector &actionProf) const;
70 void addConstTableAttr(Util::JsonArray *attrJson) const override;
71 bool addMatchTypePriority(std::optional<cstring> &matchType) const override;
72 void addActionProfs(Util::JsonArray *tablesJson) const override;
73 bool addActionProfIds(const p4configv1::Table &table,
74 Util::JsonObject *tableJson) const override;
75 void addMatchActionData(const p4configv1::Table &table, Util::JsonObject *tableJson,
76 Util::JsonArray *dataJson, P4Id maxActionParamId) const;
77
78 std::optional<bool> actProfHasSelector(P4Id actProfId) const override;
79
80 static std::optional<ActionProf> fromDPDKActionProfile(
81 const p4configv1::P4Info &p4info, const p4configv1::ExternInstance &externInstance) {
82 const auto &pre = externInstance.preamble();
83 p4configv1::ActionProfile actionProfile;
84 if (!externInstance.info().UnpackTo(&actionProfile)) {
85 ::error(ErrorType::ERR_NOT_FOUND,
86 "Extern instance %1% does not pack an ActionProfile object", pre.name());
87 return std::nullopt;
88 }
89 auto tableIds = collectTableIds(p4info, actionProfile.table_ids().begin(),
90 actionProfile.table_ids().end());
91 return ActionProf{pre.name(), pre.id(), actionProfile.size(), tableIds,
92 transformAnnotations(pre)};
93 };
94};
95
96} // namespace BFRT
97
98} // namespace P4
99
100#endif // DPDK_CONTROL_PLANE_BFRUNTIME_EXT_H_
Definition options.h:24
Definition bfruntime.h:270
Definition bfruntime_ext.h:30
const Util::JsonObject * genSchema() const override
Generates the schema as a Json object for the provided P4Info instance.
Definition bfruntime_ext.cpp:219
Definition json.h:111
Definition json.h:158
Definition applyOptionsPragmas.cpp:24