Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Bug in semantic check and P4 1.1 syntax for test programs #15

Open
wants to merge 1 commit into
base: p4v1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion p4_hlir/frontend/semantic_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ def check_P4Register(self, symbols, header_fields, objects, types = None):

if self.layout:
p4_type = self.layout.check_ts(symbols, header_fields, objects)
if p4_type is not None and p4_type.type_ == Types.header_type:
if p4_type is None or p4_type.type_ != Types.header_type:
error_msg = "Error in register %s defined in file %s at line %d:"\
" layout attribute needs to refer to header type"\
% (self.name, self.filename, self.lineno)
Expand Down
8 changes: 4 additions & 4 deletions tests/control_flow_opt.p4
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "includes/headers.p4"
#include "includes/parser.p4"

action hop(ttl, egress_spec) {
add_to_field(ttl, -1);
action hop(bit<8> ttl, bit<8> egress_spec) {
modify_field(ttl, ttl - 1);
modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF);
}

action hop_ipv4(egress_spec) {
action hop_ipv4(bit<8> egress_spec) {
hop(ipv4.ttl, egress_spec);
}

Expand Down Expand Up @@ -85,4 +85,4 @@ control ingress {

control egress {

}
}
100 changes: 50 additions & 50 deletions tests/includes/headers.p4
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
header_type ethernet_t {
fields {
dstAddr : 48;
srcAddr : 48;
etherType : 16;
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}
}

header_type vlan_tag_t {
fields {
pcp : 3;
cfi : 1;
vid : 12;
etherType : 16;
bit<3> pcp;
bit<1> cfi;
bit<12> vid;
bit<16> etherType;
}
}

header_type ipv4_t {
fields {
version : 4;
ihl : 4;
diffserv : 8;
totalLen : 16;
identification : 16;
flags : 3;
fragOffset : 13;
ttl : 8;
protocol : 8;
hdrChecksum : 16;
srcAddr : 32;
dstAddr: 32;
bit<4> version;
bit<4> ihl;
bit<8> diffserv;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdrChecksum;
bit<32> srcAddr;
bit<32> dstAddr;
}
}

header_type ipv6_t {
fields {
version : 4;
trafficClass : 8;
flowLabel : 20;
payloadLen : 16;
nextHdr : 8;
hopLimit : 8;
srcAddr : 128;
dstAddr : 128;
bit<4> version;
bit<8> trafficClass;
bit<20> flowLabel;
bit<16> payloadLen;
bit<8> nextHdr;
bit<8> hopLimit;
bit<128> srcAddr;
bit<128> dstAddr;
}
}

header_type icmp_t {
fields {
hdr_type : 8;
code : 8;
hdrChecksum : 16;
bit<8> hdr_type;
bit<8> code;
bit<16> hdrChecksum;
}
}

header_type icmpv6_t {
fields {
hdr_type : 8;
code : 8;
hdrChecksum : 16;
bit<8> hdr_type;
bit<8> code;
bit<16> hdrChecksum;
}
}

header_type tcp_t {
fields {
srcPort : 16;
dstPort : 16;
seqNo : 32;
ackNo : 32;
dataOffset : 4;
res : 3;
ecn : 3;
ctrl : 6;
window : 16;
checksum : 16;
urgentPtr : 16;
bit<16> srcPort;
bit<16> dstPort;
bit<32> seqNo;
bit<32> ackNo;
bit<4> dataOffset;
bit<3> res;
bit<3> ecn;
bit<6> ctrl;
bit<16> window;
bit<16> checksum;
bit<16> urgentPtr;
}
}

header_type udp_t {
fields {
srcPort : 16;
dstPort : 16;
hdr_length : 16;
checksum : 16;
bit<16> srcPort;
bit<16> dstPort;
bit<16> hdr_length;
bit<16> checksum;
}
}

header_type routing_metadata_t {
fields {
drop : 1;
bit<1> drop;
}
}
}
12 changes: 6 additions & 6 deletions tests/stateful.p4
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "includes/headers.p4"
#include "includes/parser.p4"

action hop(ttl, egress_spec) {
add_to_field(ttl, -1);
modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF);
action hop(bit<8> ttl, bit<8> egress_spec) {
modify_field(ttl, ttl - 1);
modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF);
}

action hop_ipv4(egress_spec) {
action hop_ipv4(bit<8> egress_spec) {
hop(ipv4.ttl, egress_spec);
}

Expand Down Expand Up @@ -50,7 +50,7 @@ register reg1 {
instance_count : 100;
attributes : saturating, signed;
}

register reg2 {
layout : ipv4_t;
direct : ipv4_routing;
Expand All @@ -64,4 +64,4 @@ control ingress {

control egress {

}
}