Skip to content

Commit

Permalink
Add an example P4 program with unusual table name annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Feb 28, 2023
1 parent 2ccfc52 commit e99b304
Show file tree
Hide file tree
Showing 10 changed files with 733 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
e26a49dbf5749ee92585cec9e95ca781d377ebfd
# clang-format ir and lib folder.
7a722a3fb8205c57d7e9554fc7c62c2629720d5a
# Switched from left to right pointer alignment.
f1181a071844f759b618ed3c894cf56e2df1dd05
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ p4tools_add_xfail_reason(
p4tools_add_xfail_reason(
"testgen-p4c-bmv2"
"Exception"
# Running simple_switch_CLI: Exception Unexpected key field &
# Running simple_switch_CLI: Exception Unexpected key field &
match-on-exprs2-bmv2.p4
# Running simple_switch_CLI: Exception Unexpected key field :
# Running simple_switch_CLI: Exception Unexpected key field :
dash-pipeline.p4
# Could not find table
nonstandard_table_names-bmv2.p4
)

p4tools_add_xfail_reason(
Expand Down
113 changes: 113 additions & 0 deletions testdata/p4_16_samples/nonstandard_table_names-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <core.p4>
#include <v1model.p4>

header ethernet_t {
bit<48> dst_addr;
bit<48> src_addr;
bit<16> eth_type;
}

struct Headers {
ethernet_t eth_hdr;
}

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);
transition accept;
}
}


control tables(inout Headers h, inout Meta m, inout standard_metadata_t s) {
action increment() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 1;
}

@name("prefix|simple_table_1")
table simple_table_1 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction;
increment;
}
}
@name("@prefix@simple_table_2")
table simple_table_2 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name") ;
}
actions = {
NoAction;
increment;
}
}
@name("<>]{]prefix/simple_table_3")
table simple_table_3 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name") ;
}
actions = {
NoAction;
increment;
}
}
@name("!@#$%^&*()_+=-prefix^simple_table_1")
table simple_table_4 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name") ;
}
actions = {
NoAction;
increment;
}
}
@name("prefix◕‿◕😀ツsimple_table_1")
table simple_table_5 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name") ;
}
actions = {
NoAction;
increment;
}
}

apply {
simple_table_1.apply();
simple_table_2.apply();
simple_table_3.apply();
simple_table_4.apply();
simple_table_5.apply();
}
}


control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {

apply {
tables.apply(h, m, sm);
}
}

control vrfy(inout Headers h, inout Meta m) { apply {} }

control update(inout Headers h, 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;

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

header ethernet_t {
bit<48> dst_addr;
bit<48> src_addr;
bit<16> eth_type;
}

struct Headers {
ethernet_t eth_hdr;
}

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<ethernet_t>(hdr.eth_hdr);
transition accept;
}
}

control tables(inout Headers h, inout Meta m, inout standard_metadata_t s) {
action increment() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 48w1;
}
@name("prefix|simple_table_1") table simple_table_1 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction();
increment();
}
default_action = NoAction();
}
@name("@prefix@simple_table_2") table simple_table_2 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction();
increment();
}
default_action = NoAction();
}
@name("<>]{]prefix/simple_table_3") table simple_table_3 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction();
increment();
}
default_action = NoAction();
}
@name("!@#$%^&*()_+=-prefix^simple_table_1") table simple_table_4 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction();
increment();
}
default_action = NoAction();
}
@name("prefix◕‿◕😀ツsimple_table_1") table simple_table_5 {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction();
increment();
}
default_action = NoAction();
}
apply {
simple_table_1.apply();
simple_table_2.apply();
simple_table_3.apply();
simple_table_4.apply();
simple_table_5.apply();
}
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("tables") tables() tables_inst;
apply {
tables_inst.apply(h, m, sm);
}
}

control vrfy(inout Headers h, inout Meta m) {
apply {
}
}

control update(inout Headers h, 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<Headers>(h);
}
}

V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

header ethernet_t {
bit<48> dst_addr;
bit<48> src_addr;
bit<16> eth_type;
}

struct Headers {
ethernet_t eth_hdr;
}

struct Meta {
}

parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) {
state start {
pkt.extract<ethernet_t>(hdr.eth_hdr);
transition accept;
}
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@noWarn("unused") @name(".NoAction") action NoAction_2() {
}
@noWarn("unused") @name(".NoAction") action NoAction_3() {
}
@noWarn("unused") @name(".NoAction") action NoAction_4() {
}
@noWarn("unused") @name(".NoAction") action NoAction_5() {
}
@name("ingress.tables.increment") action tables_increment_0() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 48w1;
}
@name("ingress.tables.increment") action tables_increment_1() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 48w1;
}
@name("ingress.tables.increment") action tables_increment_2() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 48w1;
}
@name("ingress.tables.increment") action tables_increment_3() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 48w1;
}
@name("ingress.tables.increment") action tables_increment_4() {
h.eth_hdr.dst_addr = h.eth_hdr.dst_addr + 48w1;
}
@name("ingress.tables.prefix|simple_table_1") table tables_prefix_simple_table {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction_1();
tables_increment_0();
}
default_action = NoAction_1();
}
@name("ingress.tables.@prefix@simple_table_2") table tables__prefix_simple_table {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction_2();
tables_increment_1();
}
default_action = NoAction_2();
}
@name("ingress.tables.<>]{]prefix/simple_table_3") table tables______prefix_simple_table {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction_3();
tables_increment_2();
}
default_action = NoAction_3();
}
@name("ingress.tables.!@#$%^&*()_+=-prefix^simple_table_1") table tables_______________prefix_simple_table {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction_4();
tables_increment_3();
}
default_action = NoAction_4();
}
@name("ingress.tables.prefix◕‿◕😀ツsimple_table_1") table tables_prefix________________simple_table {
key = {
h.eth_hdr.eth_type: exact @name("dummy_name");
}
actions = {
NoAction_5();
tables_increment_4();
}
default_action = NoAction_5();
}
apply {
tables_prefix_simple_table.apply();
tables__prefix_simple_table.apply();
tables______prefix_simple_table.apply();
tables_______________prefix_simple_table.apply();
tables_prefix________________simple_table.apply();
}
}

control vrfy(inout Headers h, inout Meta m) {
apply {
}
}

control update(inout Headers h, 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<Headers>(h);
}
}

V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
Loading

0 comments on commit e99b304

Please sign in to comment.