-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[P4Testgen] Add EliminateInvalidHeaders midend pass (#4239)
* testgen: Add EliminateInvalidHeaders midend pass * Add BMV2 test with {#} literal
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
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
68 changes: 68 additions & 0 deletions
68
backends/p4tools/modules/testgen/targets/bmv2/test/p4-programs/bmv2_valid_lit.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,68 @@ | ||
#include <core.p4> | ||
#include <v1model.p4> | ||
|
||
header ethernet_t { | ||
bit<48> dst_addr; | ||
bit<48> src_addr; | ||
bit<16> eth_type; | ||
} | ||
|
||
header h0_t { | ||
bit<32> f0; | ||
bit<32> f1; | ||
} | ||
|
||
struct headers { | ||
ethernet_t eth_hdr; | ||
h0_t h0; | ||
} | ||
|
||
struct Meta {} | ||
|
||
parser p(packet_in pkt, out headers hdr, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
transition parse_hdrs; | ||
} | ||
state parse_hdrs { | ||
pkt.extract(hdr.eth_hdr); | ||
pkt.extract(hdr.h0); | ||
transition select(hdr.h0.f0) { | ||
0: invalidate; | ||
default: accept; | ||
} | ||
} | ||
state invalidate { | ||
hdr.h0 = (h0_t){#}; | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingress(inout headers h, inout Meta m, inout standard_metadata_t sm) { | ||
bit<32> a = 0; | ||
apply { | ||
if (h.eth_hdr.isValid()) | ||
a = a | 1; | ||
if (h.h0 == (h0_t){#}) | ||
a = a | 2; | ||
h.eth_hdr = (ethernet_t){#}; | ||
h.h0.setValid(); | ||
h.h0.f0 = a; | ||
} | ||
} | ||
|
||
control vrfy(inout headers h, inout Meta m) { | ||
apply {} | ||
} | ||
|
||
control update(inout headers hdr, inout Meta m) { apply { | ||
}} | ||
|
||
control egress(inout headers h, inout Meta m, inout standard_metadata_t sm) { apply {} } | ||
|
||
control deparser(packet_out pkt, in headers h) { | ||
apply { | ||
pkt.emit(h); | ||
} | ||
} | ||
V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; | ||
|