Skip to content
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

Allow to use simple types inside out struct as a parser's parameter #3134

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions backends/bmv2/simple_switch/simpleSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,18 +1129,6 @@ SimpleSwitchBackend::convert(const IR::ToplevelBlock* tlb) {
"%1%: expected type to be a struct", headersParam->type);
return;
}
LOG2("Headers type is " << st);
for (auto f : st->fields) {
auto t = typeMap->getType(f, true);
if (!t->is<IR::Type_Header>() &&
!t->is<IR::Type_Stack>() &&
!t->is<IR::Type_HeaderUnion>()) {
::error(ErrorType::ERR_EXPECTED,
"%1%: the type should be a struct of headers, stacks, or unions",
headersParam->type);
return;
}
}
}

auto evaluator = new P4::EvaluatorPass(refMap, typeMap);
Expand Down
53 changes: 53 additions & 0 deletions testdata/p4_16_samples/struct_with_st-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "v1model.p4"
struct metadata {
/* empty */
}

enum bit<7> X {
Zero = 0,
One = 1
}

header BITS {
bit<8> bt;
int<8> it;
bool b;
X x;
}

struct headers {
BITS bits;
bit<8> bt;
int<8> it;
bool b;
X x;
}

parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
state start {
packet.extract(hdr.bits);
hdr.bt = hdr.bits.bt;
hdr.it = hdr.bits.it;
hdr.b = hdr.bits.b;
hdr.x = hdr.bits.x;
transition accept;
}
}

control mau(inout headers hdr, inout metadata meta, inout standard_metadata_t sm) {
apply {}
}
control deparse(packet_out pkt, in headers hdr) {
apply {}
}
control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {}
}
control computeChecksum(inout headers hdr, inout metadata meta) {
apply {}
}
V1Switch(MyParser(), verifyChecksum(), mau(), mau(), computeChecksum(),
deparse()) main;
60 changes: 60 additions & 0 deletions testdata/p4_16_samples_outputs/struct_with_st-bmv2-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

struct metadata {
}

enum bit<7> X {
Zero = 7w0,
One = 7w1
}

header BITS {
bit<8> bt;
int<8> it;
bool b;
X x;
}

struct headers {
BITS bits;
bit<8> bt;
int<8> it;
bool b;
X x;
}

parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
state start {
packet.extract<BITS>(hdr.bits);
hdr.bt = hdr.bits.bt;
hdr.it = hdr.bits.it;
hdr.b = hdr.bits.b;
hdr.x = hdr.bits.x;
transition accept;
}
}

control mau(inout headers hdr, inout metadata meta, inout standard_metadata_t sm) {
apply {
}
}

control deparse(packet_out pkt, 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>(MyParser(), verifyChecksum(), mau(), mau(), computeChecksum(), deparse()) main;

60 changes: 60 additions & 0 deletions testdata/p4_16_samples_outputs/struct_with_st-bmv2-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

struct metadata {
}

enum bit<7> X {
Zero = 7w0,
One = 7w1
}

header BITS {
bit<8> bt;
int<8> it;
bool b;
X x;
}

struct headers {
BITS bits;
bit<8> bt;
int<8> it;
bool b;
X x;
}

parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
state start {
packet.extract<BITS>(hdr.bits);
hdr.bt = hdr.bits.bt;
hdr.it = hdr.bits.it;
hdr.b = hdr.bits.b;
hdr.x = hdr.bits.x;
transition accept;
}
}

control mau(inout headers hdr, inout metadata meta, inout standard_metadata_t sm) {
apply {
}
}

control deparse(packet_out pkt, 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>(MyParser(), verifyChecksum(), mau(), mau(), computeChecksum(), deparse()) main;

55 changes: 55 additions & 0 deletions testdata/p4_16_samples_outputs/struct_with_st-bmv2-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

struct metadata {
}

header BITS {
bit<8> bt;
int<8> it;
bool b;
bit<7> x;
}

struct headers {
BITS bits;
bit<8> bt;
int<8> it;
bool b;
bit<7> x;
}

parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
state start {
packet.extract<BITS>(hdr.bits);
hdr.bt = hdr.bits.bt;
hdr.it = hdr.bits.it;
hdr.b = hdr.bits.b;
hdr.x = hdr.bits.x;
transition accept;
}
}

control mau(inout headers hdr, inout metadata meta, inout standard_metadata_t sm) {
apply {
}
}

control deparse(packet_out pkt, 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>(MyParser(), verifyChecksum(), mau(), mau(), computeChecksum(), deparse()) main;

60 changes: 60 additions & 0 deletions testdata/p4_16_samples_outputs/struct_with_st-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

struct metadata {
}

enum bit<7> X {
Zero = 0,
One = 1
}

header BITS {
bit<8> bt;
int<8> it;
bool b;
X x;
}

struct headers {
BITS bits;
bit<8> bt;
int<8> it;
bool b;
X x;
}

parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
state start {
packet.extract(hdr.bits);
hdr.bt = hdr.bits.bt;
hdr.it = hdr.bits.it;
hdr.b = hdr.bits.b;
hdr.x = hdr.bits.x;
transition accept;
}
}

control mau(inout headers hdr, inout metadata meta, inout standard_metadata_t sm) {
apply {
}
}

control deparse(packet_out pkt, in headers hdr) {
apply {
}
}

control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}

V1Switch(MyParser(), verifyChecksum(), mau(), mau(), computeChecksum(), deparse()) main;

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg_info {
arch: "v1model"
}