[ONOS-6596] Port example P4 programs from P4_14 to P4_16
Change-Id: I74485ea66894b425fa9f6508a67cb38dbef85a4f
diff --git a/tools/test/p4src/Makefile b/tools/test/p4src/p4-14/Makefile
similarity index 100%
rename from tools/test/p4src/Makefile
rename to tools/test/p4src/p4-14/Makefile
diff --git a/tools/test/p4src/default.p4 b/tools/test/p4src/p4-14/default.p4
similarity index 100%
rename from tools/test/p4src/default.p4
rename to tools/test/p4src/p4-14/default.p4
diff --git a/tools/test/p4src/ecmp.p4 b/tools/test/p4src/p4-14/ecmp.p4
similarity index 100%
rename from tools/test/p4src/ecmp.p4
rename to tools/test/p4src/p4-14/ecmp.p4
diff --git a/tools/test/p4src/empty.p4 b/tools/test/p4src/p4-14/empty.p4
similarity index 100%
rename from tools/test/p4src/empty.p4
rename to tools/test/p4src/p4-14/empty.p4
diff --git a/tools/test/p4src/include/actions.p4 b/tools/test/p4src/p4-14/include/actions.p4
similarity index 100%
rename from tools/test/p4src/include/actions.p4
rename to tools/test/p4src/p4-14/include/actions.p4
diff --git a/tools/test/p4src/include/defines.p4 b/tools/test/p4src/p4-14/include/defines.p4
similarity index 100%
rename from tools/test/p4src/include/defines.p4
rename to tools/test/p4src/p4-14/include/defines.p4
diff --git a/tools/test/p4src/include/headers.p4 b/tools/test/p4src/p4-14/include/headers.p4
similarity index 100%
rename from tools/test/p4src/include/headers.p4
rename to tools/test/p4src/p4-14/include/headers.p4
diff --git a/tools/test/p4src/include/parser.p4 b/tools/test/p4src/p4-14/include/parser.p4
similarity index 100%
rename from tools/test/p4src/include/parser.p4
rename to tools/test/p4src/p4-14/include/parser.p4
diff --git a/tools/test/p4src/include/port_counters.p4 b/tools/test/p4src/p4-14/include/port_counters.p4
similarity index 100%
rename from tools/test/p4src/include/port_counters.p4
rename to tools/test/p4src/p4-14/include/port_counters.p4
diff --git a/tools/test/p4src/p4c-out/.gitignore b/tools/test/p4src/p4-14/p4c-out/.gitignore
similarity index 93%
rename from tools/test/p4src/p4c-out/.gitignore
rename to tools/test/p4src/p4-14/p4c-out/.gitignore
index f02ec97..dfbb6b2 100644
--- a/tools/test/p4src/p4c-out/.gitignore
+++ b/tools/test/p4src/p4-14/p4c-out/.gitignore
@@ -1,2 +1,2 @@
*.json
-*.p4info
\ No newline at end of file
+*.p4info
diff --git a/tools/test/p4src/wcmp.p4 b/tools/test/p4src/p4-14/wcmp.p4
similarity index 100%
rename from tools/test/p4src/wcmp.p4
rename to tools/test/p4src/p4-14/wcmp.p4
diff --git a/tools/test/p4src/p4-16/Makefile b/tools/test/p4src/p4-16/Makefile
new file mode 100644
index 0000000..9214804
--- /dev/null
+++ b/tools/test/p4src/p4-16/Makefile
@@ -0,0 +1,25 @@
+all: default.json empty.json ecmp.json wcmp.json
+
+default.json: default.p4
+ p4c-bm2-ss -o p4c-out/default.json \
+ --p4runtime-file p4c-out/default.p4info --p4runtime-format text \
+ default.p4
+
+empty.json: empty.p4
+ p4c-bm2-ss -o p4c-out/empty.json \
+ --p4runtime-file p4c-out/empty.p4info --p4runtime-format text \
+ empty.p4
+
+ecmp.json: ecmp.p4
+ p4c-bm2-ss -o p4c-out/ecmp.json \
+ --p4runtime-file p4c-out/ecmp.p4info --p4runtime-format text \
+ ecmp.p4
+
+wcmp.json: wcmp.p4
+ p4c-bm2-ss -o p4c-out/wcmp.json \
+ --p4runtime-file p4c-out/wcmp.p4info --p4runtime-format text \
+ wcmp.p4
+
+clean:
+ rm -rf p4c-out/*.json
+ rm -rf p4c-out/*.p4info
diff --git a/tools/test/p4src/p4-16/default.p4 b/tools/test/p4src/p4-16/default.p4
new file mode 100644
index 0000000..71a48b5
--- /dev/null
+++ b/tools/test/p4src/p4-16/default.p4
@@ -0,0 +1,42 @@
+#include <core.p4>
+#include <v1model.p4>
+#include "include/defines.p4"
+#include "include/headers.p4"
+#include "include/parsers.p4"
+#include "include/port_counters.p4"
+#include "include/checksums.p4"
+#include "include/actions.p4"
+
+control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ direct_counter(CounterType.packets) table0_counter;
+
+ table table0 {
+ support_timeout = true;
+ actions = {
+ set_egress_port(standard_metadata);
+ send_to_cpu(standard_metadata);
+ drop(standard_metadata);
+ }
+ key = {
+ standard_metadata.ingress_port: ternary;
+ hdr.ethernet.dstAddr : ternary;
+ hdr.ethernet.srcAddr : ternary;
+ hdr.ethernet.etherType : ternary;
+ }
+ counters = table0_counter;
+ }
+ PortCountersControl() port_counters_control;
+ apply {
+ table0.apply();
+ port_counters_control.apply(hdr, meta, standard_metadata);
+ }
+
+}
+
+control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ apply {
+ // Nothing to do
+ }
+}
+
+V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
diff --git a/tools/test/p4src/p4-16/ecmp.p4 b/tools/test/p4src/p4-16/ecmp.p4
new file mode 100644
index 0000000..6b3e73e
--- /dev/null
+++ b/tools/test/p4src/p4-16/ecmp.p4
@@ -0,0 +1,65 @@
+#include <core.p4>
+#include <v1model.p4>
+#include "include/defines.p4"
+#include "include/headers.p4"
+#include "include/parsers.p4"
+#include "include/port_counters.p4"
+#include "include/checksums.p4"
+#include "include/actions.p4"
+
+
+control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ direct_counter(CounterType.packets) ecmp_group_table_counter;
+ direct_counter(CounterType.packets) table0_counter;
+
+ action ecmp_group(GroupId groupId, GroupSize groupSize) {
+ meta.ecmp_metadata.groupId = groupId;
+ hash(meta.ecmp_metadata.selector, HashAlgorithm.crc16, (bit<64>)0, { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort, hdr.udp.dstPort }, (bit<128>)groupSize);
+ }
+
+ table ecmp_group_table {
+ actions = {
+ set_egress_port(standard_metadata);
+ }
+ key = {
+ meta.ecmp_metadata.groupId : exact;
+ meta.ecmp_metadata.selector: exact;
+ }
+ counters = ecmp_group_table_counter;
+ }
+
+ table table0 {
+ support_timeout = true;
+ actions = {
+ ecmp_group;
+ set_egress_port(standard_metadata);
+ send_to_cpu(standard_metadata);
+ drop(standard_metadata);
+ }
+ key = {
+ standard_metadata.ingress_port: ternary;
+ hdr.ethernet.dstAddr : ternary;
+ hdr.ethernet.srcAddr : ternary;
+ hdr.ethernet.etherType : ternary;
+ }
+ counters = table0_counter;
+ }
+ PortCountersControl() port_counters_control;
+ apply {
+ switch (table0.apply().action_run) {
+ ecmp_group: {
+ ecmp_group_table.apply();
+ }
+ }
+
+ port_counters_control.apply(hdr, meta, standard_metadata);
+ }
+}
+
+control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ apply {
+ // Nothing to do
+ }
+}
+
+V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
diff --git a/tools/test/p4src/p4-16/empty.p4 b/tools/test/p4src/p4-16/empty.p4
new file mode 100644
index 0000000..09e4740
--- /dev/null
+++ b/tools/test/p4src/p4-16/empty.p4
@@ -0,0 +1,62 @@
+#include <core.p4>
+#include <v1model.p4>
+
+struct dummy_t {
+ bit<8> dummyField;
+}
+
+struct metadata {
+ dummy_t dummy_metadata;
+}
+
+struct headers {
+}
+
+parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ state start {
+ transition accept;
+ }
+}
+
+control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ action dummy_action() {
+ meta.dummy_metadata.dummyField = 8w1;
+ }
+ table table0 {
+ actions = {
+ dummy_action;
+ }
+ key = {
+ meta.dummy_metadata.dummyField: exact;
+ }
+ }
+ apply {
+ table0.apply();
+ }
+}
+
+control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ apply {
+ // Nothing to do
+ }
+}
+
+control DeparserImpl(packet_out packet, in headers hdr) {
+ apply {
+ // Nothing to do
+ }
+}
+
+control verifyChecksum(in headers hdr, inout metadata meta) {
+ apply {
+ // Nothing to do
+ }
+}
+
+control computeChecksum(inout headers hdr, inout metadata meta) {
+ apply {
+ // Nothing to do
+ }
+}
+
+V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
diff --git a/tools/test/p4src/p4-16/include/actions.p4 b/tools/test/p4src/p4-16/include/actions.p4
new file mode 100644
index 0000000..0ef0533
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/actions.p4
@@ -0,0 +1,14 @@
+#include "defines.p4"
+#include "headers.p4"
+
+action send_to_cpu(inout standard_metadata_t standard_metadata) {
+ standard_metadata.egress_spec = CPU_PORT;
+}
+
+action set_egress_port(inout standard_metadata_t standard_metadata, Port port) {
+ standard_metadata.egress_spec = port;
+}
+
+action drop(inout standard_metadata_t standard_metadata) {
+ standard_metadata.egress_spec = DROP_PORT;
+}
diff --git a/tools/test/p4src/p4-16/include/checksums.p4 b/tools/test/p4src/p4-16/include/checksums.p4
new file mode 100644
index 0000000..09365dc
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/checksums.p4
@@ -0,0 +1,17 @@
+#ifndef CHECK_SUMS
+#define CHECK_SUMS
+#include "headers.p4"
+#include "metadata.p4"
+
+control verifyChecksum(in headers hdr, inout metadata meta) {
+ apply {
+ // Nothing to do
+ }
+}
+
+control computeChecksum(inout headers hdr, inout metadata meta) {
+ apply {
+ // Nothing to do
+ }
+}
+#endif
diff --git a/tools/test/p4src/p4-16/include/defines.p4 b/tools/test/p4src/p4-16/include/defines.p4
new file mode 100644
index 0000000..24974a1
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/defines.p4
@@ -0,0 +1,10 @@
+#ifndef DEFINES
+#define DEFINES
+// Logic ports as defined in the simple_switch target
+#define MAX_PORTS 254
+#define CPU_PORT 9w255
+#define DROP_PORT 9w511
+typedef bit<16> GroupId;
+typedef bit<8> GroupSize;
+typedef bit<9> Port;
+#endif
diff --git a/tools/test/p4src/p4-16/include/headers.p4 b/tools/test/p4src/p4-16/include/headers.p4
new file mode 100644
index 0000000..d497370
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/headers.p4
@@ -0,0 +1,58 @@
+#ifndef HEADERS
+#define HEADERS
+struct intrinsic_metadata_t {
+ bit<32> ingress_global_timestamp;
+ bit<32> lf_field_list;
+ bit<16> mcast_grp;
+ bit<16> egress_rid;
+}
+
+header ethernet_t {
+ bit<48> dstAddr;
+ bit<48> srcAddr;
+ bit<16> etherType;
+}
+
+header ipv4_t {
+ 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 tcp_t {
+ 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 udp_t {
+ bit<16> srcPort;
+ bit<16> dstPort;
+ bit<16> length_;
+ bit<16> checksum;
+}
+
+struct headers {
+ ethernet_t ethernet;
+ ipv4_t ipv4;
+ tcp_t tcp;
+ udp_t udp;
+}
+#endif
diff --git a/tools/test/p4src/p4-16/include/metadata.p4 b/tools/test/p4src/p4-16/include/metadata.p4
new file mode 100644
index 0000000..e08057c
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/metadata.p4
@@ -0,0 +1,20 @@
+#ifndef METADATA
+#define METADATA
+
+struct ecmp_metadata_t {
+ bit<16> groupId;
+ bit<16> selector;
+}
+
+struct wcmp_meta_t {
+ bit<16> groupId;
+ bit<8> numBits;
+ bit<64> selector;
+}
+
+struct metadata {
+ ecmp_metadata_t ecmp_metadata;
+ wcmp_meta_t wcmp_meta;
+ intrinsic_metadata_t intrinsic_metadata;
+}
+#endif
diff --git a/tools/test/p4src/p4-16/include/parsers.p4 b/tools/test/p4src/p4-16/include/parsers.p4
new file mode 100644
index 0000000..e9fbc6f
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/parsers.p4
@@ -0,0 +1,51 @@
+#ifndef PARSERS
+#define PARSERS
+#include "headers.p4"
+#include "metadata.p4"
+
+#define ETH_TYPE_IPV4 16w0x0800
+#define IP_TYPE_TCP 8w6
+#define IP_TYPE_UDP 8w17
+
+parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ state parse_ethernet {
+ packet.extract(hdr.ethernet);
+ transition select(hdr.ethernet.etherType) {
+ ETH_TYPE_IPV4: parse_ipv4;
+ default: accept;
+ }
+ }
+
+ state parse_ipv4 {
+ packet.extract(hdr.ipv4);
+ transition select(hdr.ipv4.protocol) {
+ IP_TYPE_TCP: parse_tcp;
+ IP_TYPE_UDP: parse_udp;
+ default: accept;
+ }
+ }
+
+ state parse_tcp {
+ packet.extract(hdr.tcp);
+ transition accept;
+ }
+
+ state parse_udp {
+ packet.extract(hdr.udp);
+ transition accept;
+ }
+
+ state start {
+ transition parse_ethernet;
+ }
+}
+
+control DeparserImpl(packet_out packet, in headers hdr) {
+ apply {
+ packet.emit(hdr.ethernet);
+ packet.emit(hdr.ipv4);
+ packet.emit(hdr.udp);
+ packet.emit(hdr.tcp);
+ }
+}
+#endif
diff --git a/tools/test/p4src/p4-16/include/port_counters.p4 b/tools/test/p4src/p4-16/include/port_counters.p4
new file mode 100644
index 0000000..90916ba
--- /dev/null
+++ b/tools/test/p4src/p4-16/include/port_counters.p4
@@ -0,0 +1,16 @@
+#ifndef PORT_COUNTERS
+#define PORT_COUNTERS
+#include "defines.p4"
+
+control PortCountersControl(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ counter(MAX_PORTS, CounterType.packets) egress_port_counter;
+ counter(MAX_PORTS, CounterType.packets) ingress_port_counter;
+
+ apply {
+ if (standard_metadata.egress_spec < MAX_PORTS) {
+ ingress_port_counter.count((bit<32>)standard_metadata.ingress_port);
+ egress_port_counter.count((bit<32>)standard_metadata.egress_spec);
+ }
+ }
+}
+#endif
diff --git a/tools/test/p4src/p4c-out/.gitignore b/tools/test/p4src/p4-16/p4c-out/.gitignore
similarity index 93%
copy from tools/test/p4src/p4c-out/.gitignore
copy to tools/test/p4src/p4-16/p4c-out/.gitignore
index f02ec97..dfbb6b2 100644
--- a/tools/test/p4src/p4c-out/.gitignore
+++ b/tools/test/p4src/p4-16/p4c-out/.gitignore
@@ -1,2 +1,2 @@
*.json
-*.p4info
\ No newline at end of file
+*.p4info
diff --git a/tools/test/p4src/p4-16/wcmp.p4 b/tools/test/p4src/p4-16/wcmp.p4
new file mode 100644
index 0000000..6dff6f1
--- /dev/null
+++ b/tools/test/p4src/p4-16/wcmp.p4
@@ -0,0 +1,72 @@
+#include <core.p4>
+#include <v1model.p4>
+#include "include/defines.p4"
+#include "include/headers.p4"
+#include "include/parsers.p4"
+#include "include/port_counters.p4"
+#include "include/checksums.p4"
+#include "include/actions.p4"
+
+#define SELECTOR_WIDTH 64
+const bit<SELECTOR_WIDTH> ONE = 64w1;
+
+control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ direct_counter(CounterType.packets) table0_counter;
+ direct_counter(CounterType.packets) wcmp_group_table_counter;
+
+ action wcmp_group(GroupId groupId) {
+ meta.wcmp_meta.groupId = groupId;
+ hash(meta.wcmp_meta.numBits, HashAlgorithm.crc16, (bit<64>)2, { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort, hdr.udp.dstPort }, (bit<128>)62);
+ }
+
+ action wcmp_set_selector() {
+ meta.wcmp_meta.selector = ((ONE << meta.wcmp_meta.numBits) - ONE) << (SELECTOR_WIDTH - meta.wcmp_meta.numBits);
+ }
+
+ table table0 {
+ support_timeout = true;
+ actions = {
+ set_egress_port(standard_metadata);
+ wcmp_group;
+ send_to_cpu(standard_metadata);
+ drop(standard_metadata);
+ }
+ key = {
+ standard_metadata.ingress_port: ternary;
+ hdr.ethernet.dstAddr : ternary;
+ hdr.ethernet.srcAddr : ternary;
+ hdr.ethernet.etherType : ternary;
+ }
+ counters = table0_counter;
+ }
+
+ table wcmp_group_table {
+ actions = {
+ set_egress_port(standard_metadata);
+ }
+ key = {
+ meta.wcmp_meta.groupId : exact;
+ meta.wcmp_meta.selector: lpm;
+ }
+ counters = wcmp_group_table_counter;
+ }
+
+ PortCountersControl() port_counters_control;
+ apply {
+ switch (table0.apply().action_run) {
+ wcmp_group: {
+ wcmp_set_selector();
+ wcmp_group_table.apply();
+ }
+ }
+ port_counters_control.apply(hdr, meta, standard_metadata);
+ }
+}
+
+control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
+ apply {
+ // Nothing to do
+ }
+}
+
+V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;