Skip to content

Commit 3b94df6

Browse files
authoredOct 19, 2024··
Use the same format for an initial config as you would for an update. (#161)
1 parent 5d698c1 commit 3b94df6

File tree

5 files changed

+70
-59
lines changed

5 files changed

+70
-59
lines changed
 

‎core/interpreter/target.cpp

+28-21
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,38 @@ std::optional<ControlPlaneConstraints> FlayTarget::computeControlPlaneConstraint
115115
// By default we only support P4Runtime parsing.
116116
if (options.controlPlaneApi() == "P4RUNTIME") {
117117
auto deserializedConfig =
118-
Protobuf::deserializeObjectFromFile<p4runtime::flaytests::Config>(confPath);
118+
Protobuf::deserializeObjectFromFile<p4::v1::WriteRequest>(confPath);
119119
if (!deserializedConfig.has_value()) {
120120
return std::nullopt;
121121
}
122122
SymbolSet symbolSet;
123-
if (P4Runtime::updateControlPlaneConstraints(deserializedConfig.value(),
124-
*compilerResult.getP4RuntimeApi().p4Info,
125-
constraints, symbolSet) != EXIT_SUCCESS) {
126-
return std::nullopt;
123+
for (const auto &msg : deserializedConfig.value().updates()) {
124+
if (P4Runtime::updateControlPlaneConstraintsWithEntityMessage(
125+
msg.entity(), *compilerResult.getP4RuntimeApi().p4Info, constraints,
126+
msg.type(), symbolSet) != EXIT_SUCCESS) {
127+
return std::nullopt;
128+
}
127129
}
130+
printInfo("Parsed %1% control plane updates for the initial configuration.",
131+
deserializedConfig.value().updates().size());
128132
return constraints;
129133
}
130134
if (options.controlPlaneApi() == "BFRUNTIME") {
131135
auto deserializedConfig =
132-
Protobuf::deserializeObjectFromFile<bfruntime::flaytests::Config>(confPath);
136+
Protobuf::deserializeObjectFromFile<bfrt_proto::WriteRequest>(confPath);
133137
if (!deserializedConfig.has_value()) {
134138
return std::nullopt;
135139
}
136140
SymbolSet symbolSet;
137-
if (BfRuntime::updateControlPlaneConstraints(deserializedConfig.value(),
138-
*compilerResult.getP4RuntimeApi().p4Info,
139-
constraints, symbolSet) != EXIT_SUCCESS) {
140-
return std::nullopt;
141+
for (const auto &msg : deserializedConfig.value().updates()) {
142+
if (BfRuntime::updateControlPlaneConstraintsWithEntityMessage(
143+
msg.entity(), *compilerResult.getP4RuntimeApi().p4Info, constraints,
144+
msg.type(), symbolSet) != EXIT_SUCCESS) {
145+
return std::nullopt;
146+
}
141147
}
148+
printInfo("Parsed %1% control plane updates for the initial configuration.",
149+
deserializedConfig.value().updates().size());
142150
return constraints;
143151
}
144152
}
@@ -151,28 +159,27 @@ std::optional<ControlPlaneConstraints> FlayTarget::computeControlPlaneConstraint
151159
MidEnd FlayTarget::mkMidEnd(const CompilerOptions &options) const {
152160
MidEnd midEnd(options);
153161
midEnd.setStopOnError(true);
154-
auto *refMap = midEnd.getRefMap();
155162
auto *typeMap = midEnd.getTypeMap();
156163
midEnd.addPasses({
157164
// Sort call arguments according to the order of the function's parameters.
158-
new P4::OrderArguments(refMap, typeMap),
165+
new P4::OrderArguments(typeMap),
159166
// Replace any slices in the left side of assignments and convert them to casts.
160-
new P4::RemoveLeftSlices(refMap, typeMap),
167+
new P4::RemoveLeftSlices(typeMap),
161168
new PassRepeated({
162169
// Local copy propagation and dead-code elimination.
163170
// Skip this if skipSideEffectOrdering is set.
164171
// TODO: Pass FlayOptions as argument here.
165172
FlayOptions::get().skipSideEffectOrdering()
166173
? nullptr
167174
: new P4::LocalCopyPropagation(
168-
refMap, typeMap, nullptr,
175+
typeMap, nullptr,
169176
[](const Visitor::Context * /*context*/, const IR::Expression * /*expr*/) {
170177
return true;
171178
}),
172179
// Simplify control flow that has constants as conditions.
173180
new P4::SimplifyControlFlow(typeMap),
174181
// Compress member access to struct expressions.
175-
new P4::ConstantFolding(refMap, typeMap),
182+
new P4::ConstantFolding(typeMap),
176183
}),
177184
});
178185
return midEnd;
@@ -186,11 +193,11 @@ PassManager FlayTarget::mkPrivateMidEnd(const CompilerOptions &options, P4::Refe
186193
midEnd.addDebugHook(options.getDebugHook(), true);
187194
midEnd.addPasses({
188195
// Replace serializable enum constants with their values.
189-
new P4::EliminateSerEnums(refMap, typeMap),
196+
new P4::EliminateSerEnums(typeMap),
190197
// Replace types introduced by 'type' with 'typedef'.
191-
new P4::EliminateNewtype(refMap, typeMap),
198+
new P4::EliminateNewtype(typeMap),
192199
// Make sure that we have no TypeDef left in the program.
193-
new P4::EliminateTypedef(refMap, typeMap),
200+
new P4::EliminateTypedef(typeMap),
194201
// Remove exit statements from the program.
195202
// TODO: We should not depend on this pass. It has bugs.
196203
new P4::RemoveExits(typeMap),
@@ -199,11 +206,11 @@ PassManager FlayTarget::mkPrivateMidEnd(const CompilerOptions &options, P4::Refe
199206
new P4::ParsersUnroll(true, refMap, typeMap),
200207
new P4::TypeChecking(refMap, typeMap, true),
201208
// Convert enums and errors to bit<32>.
202-
new P4::ConvertEnums(refMap, typeMap, new EnumOn32Bits()),
203-
new P4::ConvertErrors(refMap, typeMap, new ErrorOn32Bits()),
209+
new P4::ConvertEnums(typeMap, new EnumOn32Bits()),
210+
new P4::ConvertErrors(typeMap, new ErrorOn32Bits()),
204211
// Simplify header stack assignments with runtime indices into conditional statements.
205212
// TODO: Get rid of this pass.
206-
new P4::HSIndexSimplifier(refMap, typeMap),
213+
new P4::HSIndexSimplifier(typeMap),
207214
// Parse BMv2-specific annotations.
208215
new BMV2::ParseAnnotations(),
209216
// Convert Type_Varbits into a type that contains information about the assigned width.

‎targets/bmv2/test/testdata/issue2345-2.ref

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Eliminated node at line 40: return;
22
Replaced node at line 39: if (h.eth_hdr.eth_type == 1) { with 2
3-
statement_count_before:17
4-
statement_count_after:17
3+
statement_count_before:13
4+
statement_count_after:13
55
cyclomatic_complexity:1
66
num_parsers_paths:1
77
num_updates_processed:0

‎targets/tofino/test/programs/research/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ set (FLAY_TOFINO_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
8484

8585
set(TNA_RESEARCH_TESTS
8686
${switcharoo_SOURCE_DIR}/p4src/switcharoo.p4
87-
${p4sta_SOURCE_DIR}/stamper_targets/Wedge100B65/PLEASE_COPY/tofino_stamper_v1_2_0.p4
87+
${p4sta_SOURCE_DIR}/stamper_targets/Wedge100B65/p4_files/v1.2.1/tofino_stamper_v1_2_1.p4
8888
${p4_projects_SOURCE_DIR}/RTT-tofino/p4src/RTT.p4
8989
${p4_projects_SOURCE_DIR}/PRECISION-tofino/p4src/PRECISION.p4
9090
${p4_projects_SOURCE_DIR}/P40f-tofino/p40f_tofino.p4

‎targets/tofino/test/testdata/tofino_stamper_v1_2_0.ref

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Eliminated node at line 470: t_l1_forwarding.apply();
2+
Eliminated node at line 471: t_l2_forwarding.apply();
3+
Eliminated node at line 475: t_l3_forwarding.apply();
4+
Eliminated node at line 480: t_add_empty_timestamp_tcp.apply();
5+
Eliminated node at line 481: if(meta.l4_metadata.new_offset > 0){
6+
Eliminated node at line 487: t_timestamp2_tcp.apply();
7+
Eliminated node at line 493: t_add_empty_timestamp_udp.apply();
8+
Eliminated node at line 496: t_timestamp2_udp.apply();
9+
Eliminated node at line 501: if(meta.l4_metadata.added_empty_header == 1w0x1 || meta.l4_metadata.timestamp2 == 1w0x1){
10+
Eliminated node at line 505: if(meta.l4_metadata.timestamp2 == 1w0x1){
11+
Eliminated node at line 523: if(meta.l4_metadata.added_empty_header == 1w0x1){
12+
Eliminated node at line 555: if(meta.l4_metadata.updateChecksum == 1w0x1){
13+
Eliminated node at line 994: if(hdr.gtpu.isValid()&&hdr.tcp.isValid()&&hdr.ext_host_stats.isValid()){ //indicates TCP encapsulated in GTP-U and to ext host
14+
Eliminated node at line 1008: broadcast_mac.apply();
15+
Eliminated node at line 1011: if (hdr.ext_host_stats.isValid()){
16+
Eliminated node at line 1057: t_mark_duplicate.apply();
17+
Eliminated node at line 1086: if(meta.l4_metadata.updateEgressIPChecksum == 1w0x1){
18+
Replaced node at line 261: } else if(meta.timestamp_metadata.delta < min_value) { with 0
19+
Replaced node at line 270: if (meta.timestamp_metadata.delta > max_value) { with 0
20+
Replaced node at line 281: if(counter >= (bit<32>)meta.l4_metadata.threshold_multicast) { with 0
21+
Replaced node at line 414: ig_intr_tm_md.ucast_egress_port : exact; with 0
22+
Replaced node at line 436: ig_intr_tm_md.ucast_egress_port : exact; with 0
23+
Replaced node at line 457: ig_intr_tm_md.ucast_egress_port : exact; with 0
24+
Replaced node at line 481: if(meta.l4_metadata.new_offset > 0){ with 0
25+
Replaced node at line 486: if(hdr.tcp_options_128bit_custom.myType == 16w0x0f10 && meta.l4_metadata.added_empty_header == 0){ with 0
26+
Replaced node at line 495: if(hdr.tcp_options_128bit_custom.myType == 16w0x0f10 && meta.l4_metadata.added_empty_header == 0){ with 0
27+
Replaced node at line 501: if(meta.l4_metadata.added_empty_header == 1w0x1 || meta.l4_metadata.timestamp2 == 1w0x1){ with 0
28+
Replaced node at line 501: if(meta.l4_metadata.added_empty_header == 1w0x1 || meta.l4_metadata.timestamp2 == 1w0x1){ with 0
29+
Replaced node at line 505: if(meta.l4_metadata.timestamp2 == 1w0x1){ with 0
30+
Replaced node at line 523: if(meta.l4_metadata.added_empty_header == 1w0x1){ with 0
31+
Replaced node at line 555: if(meta.l4_metadata.updateChecksum == 1w0x1){ with 0
32+
Replaced node at line 1086: if(meta.l4_metadata.updateEgressIPChecksum == 1w0x1){ with 0
33+
statement_count_before:196
34+
statement_count_after:164
35+
cyclomatic_complexity:73
36+
num_parsers_paths:130
37+
num_updates_processed:0
38+
num_respecializations:0
39+

0 commit comments

Comments
 (0)
Please sign in to comment.