Skip to content

Commit 18c7f9e

Browse files
committed
update test as per the guidelines
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
1 parent 34d5649 commit 18c7f9e

14 files changed

+618
-5
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <core.p4>
2+
#define V1MODEL_VERSION 20180101
3+
#include <v1model.p4>
4+
5+
typedef bit<48> EthernetAddress;
6+
header Ethernet_h {
7+
EthernetAddress dstAddr;
8+
EthernetAddress srcAddr;
9+
bit<16> etherType;
10+
}
11+
12+
struct Parsed_packet {
13+
Ethernet_h ethernet;
14+
}
15+
16+
struct mystruct1 {
17+
bit<4> a;
18+
bit<4> b;
19+
bit<32> c;
20+
bit<32> d;
21+
}
22+
23+
control DeparserI(packet_out packet, in Parsed_packet hdr) {
24+
apply {
25+
packet.emit<Ethernet_h>(hdr.ethernet);
26+
}
27+
}
28+
29+
parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
30+
state start {
31+
pkt.extract<Ethernet_h>(hdr.ethernet);
32+
transition accept;
33+
}
34+
}
35+
36+
control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
37+
action a1(in bit<32> x) {
38+
meta.b = meta.b + (bit<4>)x;
39+
meta.b = (bit<4>)((bit<32>)meta.b + x);
40+
}
41+
action b(inout bit<32> x, bit<8> data) {
42+
meta.a = meta.a ^ (bit<4>)x ^ (bit<4>)data;
43+
}
44+
table t1 {
45+
key = {
46+
hdr.ethernet.srcAddr: exact @name("hdr.ethernet.srcAddr");
47+
}
48+
actions = {
49+
a1((bit<32>)meta.a);
50+
b(meta.c);
51+
}
52+
default_action = b(meta.c, (bit<8>)meta.d);
53+
}
54+
apply {
55+
t1.apply();
56+
}
57+
}
58+
59+
control cEgress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
60+
apply {
61+
}
62+
}
63+
64+
control vc(inout Parsed_packet hdr, inout mystruct1 meta) {
65+
apply {
66+
}
67+
}
68+
69+
control uc(inout Parsed_packet hdr, inout mystruct1 meta) {
70+
apply {
71+
}
72+
}
73+
74+
V1Switch<Parsed_packet, mystruct1>(parserI(), vc(), cIngress(), cEgress(), uc(), DeparserI()) main;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <core.p4>
2+
#define V1MODEL_VERSION 20180101
3+
#include <v1model.p4>
4+
5+
typedef bit<48> EthernetAddress;
6+
header Ethernet_h {
7+
EthernetAddress dstAddr;
8+
EthernetAddress srcAddr;
9+
bit<16> etherType;
10+
}
11+
12+
struct Parsed_packet {
13+
Ethernet_h ethernet;
14+
}
15+
16+
struct mystruct1 {
17+
bit<4> a;
18+
bit<4> b;
19+
bit<32> c;
20+
bit<32> d;
21+
}
22+
23+
control DeparserI(packet_out packet, in Parsed_packet hdr) {
24+
apply {
25+
packet.emit<Ethernet_h>(hdr.ethernet);
26+
}
27+
}
28+
29+
parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
30+
state start {
31+
pkt.extract<Ethernet_h>(hdr.ethernet);
32+
transition accept;
33+
}
34+
}
35+
36+
control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
37+
@name("cIngress.x") bit<32> x_0;
38+
@name("cIngress.x") bit<32> x_1;
39+
@name("cIngress.a1") action a1() {
40+
x_0 = (bit<32>)meta.a;
41+
meta.b = meta.b + (bit<4>)x_0;
42+
meta.b = (bit<4>)((bit<32>)meta.b + x_0);
43+
}
44+
@name("cIngress.b") action b_1(@name("data") bit<8> data_1) {
45+
x_1 = meta.c;
46+
meta.a = meta.a ^ (bit<4>)x_1 ^ (bit<4>)data_1;
47+
meta.c = x_1;
48+
}
49+
@name("cIngress.t1") table t1_0 {
50+
key = {
51+
hdr.ethernet.srcAddr: exact @name("hdr.ethernet.srcAddr");
52+
}
53+
actions = {
54+
a1();
55+
b_1();
56+
}
57+
default_action = b_1((bit<8>)meta.d);
58+
}
59+
apply {
60+
t1_0.apply();
61+
}
62+
}
63+
64+
control cEgress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
65+
apply {
66+
}
67+
}
68+
69+
control vc(inout Parsed_packet hdr, inout mystruct1 meta) {
70+
apply {
71+
}
72+
}
73+
74+
control uc(inout Parsed_packet hdr, inout mystruct1 meta) {
75+
apply {
76+
}
77+
}
78+
79+
V1Switch<Parsed_packet, mystruct1>(parserI(), vc(), cIngress(), cEgress(), uc(), DeparserI()) main;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <core.p4>
2+
#define V1MODEL_VERSION 20180101
3+
#include <v1model.p4>
4+
5+
header Ethernet_h {
6+
bit<48> dstAddr;
7+
bit<48> srcAddr;
8+
bit<16> etherType;
9+
}
10+
11+
struct Parsed_packet {
12+
Ethernet_h ethernet;
13+
}
14+
15+
struct mystruct1 {
16+
bit<4> a;
17+
bit<4> b;
18+
bit<32> c;
19+
bit<32> d;
20+
}
21+
22+
control DeparserI(packet_out packet, in Parsed_packet hdr) {
23+
apply {
24+
packet.emit<Ethernet_h>(hdr.ethernet);
25+
}
26+
}
27+
28+
parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
29+
state start {
30+
pkt.extract<Ethernet_h>(hdr.ethernet);
31+
transition accept;
32+
}
33+
}
34+
35+
control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
36+
@name("cIngress.a1") action a1() {
37+
meta.b = meta.b + (bit<4>)(bit<32>)meta.a;
38+
meta.b = (bit<4>)((bit<32>)meta.b + (bit<32>)meta.a);
39+
}
40+
@name("cIngress.b") action b_1(@name("data") bit<8> data_1) {
41+
meta.a = meta.a ^ (bit<4>)meta.c ^ (bit<4>)data_1;
42+
}
43+
@name("cIngress.t1") table t1_0 {
44+
key = {
45+
hdr.ethernet.srcAddr: exact @name("hdr.ethernet.srcAddr");
46+
}
47+
actions = {
48+
a1();
49+
b_1();
50+
}
51+
default_action = b_1((bit<8>)meta.d);
52+
}
53+
apply {
54+
t1_0.apply();
55+
}
56+
}
57+
58+
control cEgress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
59+
apply {
60+
}
61+
}
62+
63+
control vc(inout Parsed_packet hdr, inout mystruct1 meta) {
64+
apply {
65+
}
66+
}
67+
68+
control uc(inout Parsed_packet hdr, inout mystruct1 meta) {
69+
apply {
70+
}
71+
}
72+
73+
V1Switch<Parsed_packet, mystruct1>(parserI(), vc(), cIngress(), cEgress(), uc(), DeparserI()) main;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
issue473.p4(70): [--Werror=type-error] error: (bit<8>)meta.d: action argument must be a compile-time constant
1+
issue473.p4(70): [--Werror=unsupported] error: meta.d unsupported argument expression of type Type_Bits
22
default_action = b(meta.c, (bit<8>) meta.d);
3-
^^^^^^^^^^^^^^^
3+
^^^^^^
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# proto-file: p4/v1/p4runtime.proto
2+
# proto-message: p4.v1.WriteRequest
3+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# proto-file: p4/config/v1/p4info.proto
2+
# proto-message: p4.config.v1.P4Info
3+
4+
pkg_info {
5+
arch: "v1model"
6+
}
7+
tables {
8+
preamble {
9+
id: 39254368
10+
name: "cIngress.t1"
11+
alias: "t1"
12+
}
13+
match_fields {
14+
id: 1
15+
name: "hdr.ethernet.srcAddr"
16+
bitwidth: 48
17+
match_type: EXACT
18+
}
19+
action_refs {
20+
id: 21211318
21+
}
22+
action_refs {
23+
id: 26584255
24+
}
25+
initial_default_action {
26+
action_id: 26584255
27+
}
28+
size: 1024
29+
}
30+
actions {
31+
preamble {
32+
id: 21211318
33+
name: "cIngress.a1"
34+
alias: "a1"
35+
}
36+
}
37+
actions {
38+
preamble {
39+
id: 26584255
40+
name: "cIngress.b"
41+
alias: "b"
42+
}
43+
params {
44+
id: 1
45+
name: "data"
46+
bitwidth: 8
47+
}
48+
}
49+
type_info {
50+
}

testdata/p4_16_samples/issue5042.p4

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ control ingress(inout headers_t hdr, inout metadata_t meta,
5454
table t {
5555
key = { hdr.h.f : exact; }
5656
actions = { a; }
57-
// meta.x is NOT compile-time known, but per P4 Spec 6.8
58-
// directionless params behave as 'in' when provided by program
59-
default_action = a(meta.x);
6057
}
6158

6259
apply {
60+
a(meta.x);
6361
t.apply();
6462
}
6563
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <core.p4>
2+
#define V1MODEL_VERSION 20180101
3+
#include <v1model.p4>
4+
5+
header h_t {
6+
bit<8> f;
7+
}
8+
9+
struct metadata_t {
10+
bit<8> x;
11+
}
12+
13+
struct headers_t {
14+
h_t h;
15+
}
16+
17+
parser p(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t std_meta) {
18+
state start {
19+
pkt.extract<h_t>(hdr.h);
20+
meta.x = hdr.h.f;
21+
transition accept;
22+
}
23+
}
24+
25+
control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t std_meta) {
26+
action a(bit<8> data) {
27+
hdr.h.f = data;
28+
}
29+
table t {
30+
key = {
31+
hdr.h.f: exact @name("hdr.h.f");
32+
}
33+
actions = {
34+
a();
35+
@defaultonly NoAction();
36+
}
37+
default_action = NoAction();
38+
}
39+
apply {
40+
a(meta.x);
41+
t.apply();
42+
}
43+
}
44+
45+
control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t std_meta) {
46+
apply {
47+
}
48+
}
49+
50+
control deparser(packet_out pkt, in headers_t hdr) {
51+
apply {
52+
pkt.emit<h_t>(hdr.h);
53+
}
54+
}
55+
56+
control verifyChecksum(inout headers_t hdr, inout metadata_t meta) {
57+
apply {
58+
}
59+
}
60+
61+
control computeChecksum(inout headers_t hdr, inout metadata_t meta) {
62+
apply {
63+
}
64+
}
65+
66+
V1Switch<headers_t, metadata_t>(p(), verifyChecksum(), ingress(), egress(), computeChecksum(), deparser()) main;

0 commit comments

Comments
 (0)