-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed start state renaming for p4-14 translation using @packet_entry #3348
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e00fd09
Fixed start state renaming for p4-14 translation using @packet_entry
MichalKekely 91db5f3
Path rewritting now applies only when multi-entry is detected
MichalKekely 5b44564
Added check for renamed path (to only rename state references)
MichalKekely 9231ef5
Removed extra ;
MichalKekely File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2013-present Barefoot Networks, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
@pragma packet_entry | ||
parser start_i2e_mirrored { | ||
return start; | ||
} | ||
|
||
parser start { | ||
return ingress; | ||
} | ||
|
||
header_type start { | ||
fields { | ||
f1 : 32; | ||
} | ||
} | ||
|
||
metadata start m; | ||
|
||
action a1() { | ||
modify_field(m.f1, 1); | ||
} | ||
|
||
table t1 { | ||
actions { | ||
a1; | ||
} | ||
} | ||
|
||
control ingress { | ||
apply(t1); | ||
} | ||
|
||
control egress { | ||
} |
74 changes: 74 additions & 0 deletions
74
testdata/p4_14_samples_outputs/packet_entry_to_start-first.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
@name(".$InstanceType") enum bit<32> InstanceType_0 { | ||
START = 32w0, | ||
start_i2e_mirrored = 32w1 | ||
} | ||
|
||
#include <core.p4> | ||
#define V1MODEL_VERSION 20200408 | ||
#include <v1model.p4> | ||
|
||
@name("start") struct start_1 { | ||
bit<32> f1; | ||
} | ||
|
||
struct metadata { | ||
@name(".m") | ||
start_1 m; | ||
} | ||
|
||
struct headers { | ||
} | ||
|
||
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@name(".start") state start_0 { | ||
transition accept; | ||
} | ||
@packet_entry @name(".start_i2e_mirrored") state start_i2e_mirrored { | ||
transition start_0; | ||
} | ||
@name(".$start") state start { | ||
transition select((InstanceType_0)standard_metadata.instance_type) { | ||
InstanceType_0.START: start_0; | ||
InstanceType_0.start_i2e_mirrored: start_i2e_mirrored; | ||
} | ||
} | ||
} | ||
|
||
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@name(".a1") action a1() { | ||
meta.m.f1 = 32w1; | ||
} | ||
@name(".t1") table t1 { | ||
actions = { | ||
a1(); | ||
@defaultonly NoAction(); | ||
} | ||
default_action = NoAction(); | ||
} | ||
apply { | ||
t1.apply(); | ||
} | ||
} | ||
|
||
control DeparserImpl(packet_out packet, in headers hdr) { | ||
apply { | ||
} | ||
} | ||
|
||
control verifyChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
control computeChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; | ||
|
76 changes: 76 additions & 0 deletions
76
testdata/p4_14_samples_outputs/packet_entry_to_start-frontend.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
@name(".$InstanceType") enum bit<32> InstanceType_0 { | ||
START = 32w0, | ||
start_i2e_mirrored = 32w1 | ||
} | ||
|
||
#include <core.p4> | ||
#define V1MODEL_VERSION 20200408 | ||
#include <v1model.p4> | ||
|
||
@name("start") struct start_1 { | ||
bit<32> f1; | ||
} | ||
|
||
struct metadata { | ||
@name(".m") | ||
start_1 m; | ||
} | ||
|
||
struct headers { | ||
} | ||
|
||
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@name(".start") state start_0 { | ||
transition accept; | ||
} | ||
@packet_entry @name(".start_i2e_mirrored") state start_i2e_mirrored { | ||
transition start_0; | ||
} | ||
@name(".$start") state start { | ||
transition select((InstanceType_0)standard_metadata.instance_type) { | ||
InstanceType_0.START: start_0; | ||
InstanceType_0.start_i2e_mirrored: start_i2e_mirrored; | ||
} | ||
} | ||
} | ||
|
||
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@noWarn("unused") @name(".NoAction") action NoAction_1() { | ||
} | ||
@name(".a1") action a1() { | ||
meta.m.f1 = 32w1; | ||
} | ||
@name(".t1") table t1_0 { | ||
actions = { | ||
a1(); | ||
@defaultonly NoAction_1(); | ||
} | ||
default_action = NoAction_1(); | ||
} | ||
apply { | ||
t1_0.apply(); | ||
} | ||
} | ||
|
||
control DeparserImpl(packet_out packet, in headers hdr) { | ||
apply { | ||
} | ||
} | ||
|
||
control verifyChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
control computeChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; | ||
|
75 changes: 75 additions & 0 deletions
75
testdata/p4_14_samples_outputs/packet_entry_to_start-midend.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <core.p4> | ||
#define V1MODEL_VERSION 20200408 | ||
#include <v1model.p4> | ||
|
||
@name("start") struct start_1 { | ||
bit<32> f1; | ||
} | ||
|
||
struct metadata { | ||
bit<32> _m_f10; | ||
} | ||
|
||
struct headers { | ||
} | ||
|
||
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@name(".start") state start_0 { | ||
transition accept; | ||
} | ||
@packet_entry @name(".start_i2e_mirrored") state start_i2e_mirrored { | ||
transition start_0; | ||
} | ||
@name(".$start") state start { | ||
transition select((bit<32>)standard_metadata.instance_type) { | ||
32w0: start_0; | ||
32w1: start_i2e_mirrored; | ||
default: noMatch; | ||
} | ||
} | ||
state noMatch { | ||
verify(false, error.NoMatch); | ||
transition reject; | ||
} | ||
} | ||
|
||
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@noWarn("unused") @name(".NoAction") action NoAction_1() { | ||
} | ||
@name(".a1") action a1() { | ||
meta._m_f10 = 32w1; | ||
} | ||
@name(".t1") table t1_0 { | ||
actions = { | ||
a1(); | ||
@defaultonly NoAction_1(); | ||
} | ||
default_action = NoAction_1(); | ||
} | ||
apply { | ||
t1_0.apply(); | ||
} | ||
} | ||
|
||
control DeparserImpl(packet_out packet, in headers hdr) { | ||
apply { | ||
} | ||
} | ||
|
||
control verifyChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
control computeChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
@name(".$InstanceType") enum bit<32> InstanceType_0 { | ||
START = 0, | ||
start_i2e_mirrored = 1 | ||
} | ||
|
||
#include <core.p4> | ||
#define V1MODEL_VERSION 20200408 | ||
#include <v1model.p4> | ||
|
||
@name("start") struct start_1 { | ||
bit<32> f1; | ||
} | ||
|
||
struct metadata { | ||
@name(".m") | ||
start_1 m; | ||
} | ||
|
||
struct headers { | ||
} | ||
|
||
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@name(".start") state start_0 { | ||
transition accept; | ||
} | ||
@packet_entry @name(".start_i2e_mirrored") state start_i2e_mirrored { | ||
transition start_0; | ||
} | ||
@name(".$start") state start { | ||
transition select((InstanceType_0)standard_metadata.instance_type) { | ||
InstanceType_0.START: start_0; | ||
InstanceType_0.start_i2e_mirrored: start_i2e_mirrored; | ||
} | ||
} | ||
} | ||
|
||
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { | ||
@name(".a1") action a1() { | ||
meta.m.f1 = 32w1; | ||
} | ||
@name(".t1") table t1 { | ||
actions = { | ||
a1; | ||
} | ||
} | ||
apply { | ||
t1.apply(); | ||
} | ||
} | ||
|
||
control DeparserImpl(packet_out packet, in headers hdr) { | ||
apply { | ||
} | ||
} | ||
|
||
control verifyChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
control computeChecksum(inout headers hdr, inout metadata meta) { | ||
apply { | ||
} | ||
} | ||
|
||
V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; | ||
|
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this also rename a variable reference if the variable is named "start"?
To be safe this should check the parent context to be a SelectCase, and moreover this to be the child #1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to explicitly check if the path that is being changed is either within:
ParserState->selectExpression<PathExpression>->path
Or:
SelectCase->state<PathExpression>->path