ONOS-7058 Refactored default pipeconfs in new pipelines directory

- Minimal refactoring of P4 programs
- Removed symlinks to BMv2 JSON/P4Info
- Bumped p4c commit (which fixes known parser bug)
- Renamed "default" pipeconf to "basic" (ONOS-6818)

Change-Id: I319f8b142ab22dba9b15457e28cd62d17f78a423
diff --git a/pipelines/basic/src/main/resources/include/actions.p4 b/pipelines/basic/src/main/resources/include/actions.p4
new file mode 100644
index 0000000..d1f83b8
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/actions.p4
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ACTIONS__
+#define __ACTIONS__
+
+#include "headers.p4"
+#include "defines.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_t port) {
+    standard_metadata.egress_spec = port;
+}
+
+action _drop() {
+    mark_to_drop();
+}
+
+
+
+#endif
diff --git a/pipelines/basic/src/main/resources/include/checksums.p4 b/pipelines/basic/src/main/resources/include/checksums.p4
new file mode 100644
index 0000000..188cc9d
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/checksums.p4
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CHECKSUMS__
+#define __CHECKSUMS__
+
+#include "headers.p4"
+
+control verify_checksum_control(inout headers_t hdr,
+                                inout local_metadata_t local_metadata) {
+    apply {
+        // Assume checksum is always correct.
+    }
+}
+
+control compute_checksum_control(inout headers_t hdr,
+                                 inout local_metadata_t local_metadata) {
+    apply {
+        // No need to recompute.
+    }
+}
+
+#endif
diff --git a/pipelines/basic/src/main/resources/include/defines.p4 b/pipelines/basic/src/main/resources/include/defines.p4
new file mode 100644
index 0000000..0b0eeda
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/defines.p4
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DEFINES__
+#define __DEFINES__
+
+#define ETH_TYPE_IPV4 0x0800
+#define IP_PROTO_TCP 8w6
+#define IP_PROTO_UDP 8w17
+#define MAX_PORTS 511
+
+typedef bit<9>  port_t;
+typedef bit<16> next_hop_id_t;
+
+const port_t CPU_PORT = 255;
+
+#endif
diff --git a/pipelines/basic/src/main/resources/include/headers.p4 b/pipelines/basic/src/main/resources/include/headers.p4
new file mode 100644
index 0000000..b943c82
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/headers.p4
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HEADERS__
+#define __HEADERS__
+
+#include "defines.p4"
+
+@controller_header("packet_in")
+header packet_in_header_t {
+    bit<9> ingress_port;
+}
+
+@controller_header("packet_out")
+header packet_out_header_t {
+    bit<9> egress_port;
+}
+
+header ethernet_t {
+    bit<48> dst_addr;
+    bit<48> src_addr;
+    bit<16> ether_type;
+}
+
+header ipv4_t {
+    bit<4>  version;
+    bit<4>  ihl;
+    bit<8>  diffserv;
+    bit<16> len;
+    bit<16> identification;
+    bit<3>  flags;
+    bit<13> frag_offset;
+    bit<8>  ttl;
+    bit<8>  protocol;
+    bit<16> hdr_checksum;
+    bit<32> src_addr;
+    bit<32> dst_addr;
+}
+
+header tcp_t {
+    bit<16> src_port;
+    bit<16> dst_port;
+    bit<32> seq_no;
+    bit<32> ack_no;
+    bit<4>  data_offset;
+    bit<3>  res;
+    bit<3>  ecn;
+    bit<6>  ctrl;
+    bit<16> window;
+    bit<16> checksum;
+    bit<16> urgent_ptr;
+}
+
+header udp_t {
+    bit<16> src_port;
+    bit<16> dst_port;
+    bit<16> length_;
+    bit<16> checksum;
+}
+
+struct headers_t {
+    ethernet_t ethernet;
+    ipv4_t ipv4;
+    tcp_t tcp;
+    udp_t udp;
+    packet_out_header_t packet_out;
+    packet_in_header_t packet_in;
+}
+
+struct local_metadata_t {
+    bit<16>       l4_src_port;
+    bit<16>       l4_dst_port;
+    next_hop_id_t next_hop_id;
+    bit<16>       selector;
+}
+
+#endif
diff --git a/pipelines/basic/src/main/resources/include/packet_io.p4 b/pipelines/basic/src/main/resources/include/packet_io.p4
new file mode 100644
index 0000000..4ed681c
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/packet_io.p4
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PACKET_IO__
+#define __PACKET_IO__
+
+#include "headers.p4"
+#include "defines.p4"
+
+control packetio_ingress(inout headers_t hdr,
+                         inout standard_metadata_t standard_metadata) {
+    apply {
+        if (standard_metadata.ingress_port == CPU_PORT) {
+            standard_metadata.egress_spec = hdr.packet_out.egress_port;
+            hdr.packet_out.setInvalid();
+            exit;
+        }
+    }
+}
+
+control packetio_egress(inout headers_t hdr,
+                        inout standard_metadata_t standard_metadata) {
+    apply {
+        if (standard_metadata.egress_port == CPU_PORT) {
+            hdr.packet_in.setValid();
+            hdr.packet_in.ingress_port = standard_metadata.ingress_port;
+        }
+    }
+}
+
+#endif
\ No newline at end of file
diff --git a/pipelines/basic/src/main/resources/include/parsers.p4 b/pipelines/basic/src/main/resources/include/parsers.p4
new file mode 100644
index 0000000..601de35
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/parsers.p4
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PARSERS__
+#define __PARSERS__
+
+#include "headers.p4"
+#include "defines.p4"
+
+parser parser_impl(packet_in packet,
+                  out headers_t hdr,
+                  inout local_metadata_t local_metadata,
+                  inout standard_metadata_t standard_metadata) {
+
+    state start {
+        transition select(standard_metadata.ingress_port) {
+            CPU_PORT: parse_packet_out;
+            default: parse_ethernet;
+        }
+    }
+
+    state parse_packet_out {
+        packet.extract(hdr.packet_out);
+        transition parse_ethernet;
+    }
+
+    state parse_ethernet {
+        packet.extract(hdr.ethernet);
+        transition select(hdr.ethernet.ether_type) {
+            ETH_TYPE_IPV4: parse_ipv4;
+            default: accept;
+        }
+    }
+
+    state parse_ipv4 {
+        packet.extract(hdr.ipv4);
+        transition select(hdr.ipv4.protocol) {
+            IP_PROTO_TCP: parse_tcp;
+            IP_PROTO_UDP: parse_udp;
+            default: accept;
+        }
+    }
+
+    state parse_tcp {
+        packet.extract(hdr.tcp);
+        local_metadata.l4_src_port = hdr.tcp.src_port;
+        local_metadata.l4_dst_port = hdr.tcp.dst_port;
+        transition accept;
+    }
+
+    state parse_udp {
+        packet.extract(hdr.udp);
+        local_metadata.l4_src_port = hdr.udp.src_port;
+        local_metadata.l4_dst_port = hdr.udp.dst_port;
+        transition accept;
+    }
+}
+
+control deparser(packet_out packet, in headers_t hdr) {
+    apply {
+        packet.emit(hdr.packet_in);
+        packet.emit(hdr.ethernet);
+        packet.emit(hdr.ipv4);
+        packet.emit(hdr.tcp);
+        packet.emit(hdr.udp);
+    }
+}
+
+#endif
diff --git a/pipelines/basic/src/main/resources/include/port_counters.p4 b/pipelines/basic/src/main/resources/include/port_counters.p4
new file mode 100644
index 0000000..00e0f96
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/port_counters.p4
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PORT_COUNTERS__
+#define __PORT_COUNTERS__
+
+#include "headers.p4"
+#include "defines.p4"
+
+control port_counters_ingress(inout headers_t hdr,
+                              inout standard_metadata_t standard_metadata) {
+
+    counter(MAX_PORTS, CounterType.packets) ingress_port_counter;
+
+    apply {
+        ingress_port_counter.count((bit<32>) standard_metadata.ingress_port);
+    }
+}
+
+control port_counters_egress(inout headers_t hdr,
+                             inout standard_metadata_t standard_metadata) {
+
+    counter(MAX_PORTS, CounterType.packets) egress_port_counter;
+
+    apply {
+        egress_port_counter.count((bit<32>) standard_metadata.egress_port);
+    }
+}
+
+#endif
diff --git a/pipelines/basic/src/main/resources/include/table0.p4 b/pipelines/basic/src/main/resources/include/table0.p4
new file mode 100644
index 0000000..a004fbb
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/table0.p4
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TABLE0__
+#define __TABLE0__
+
+#include "headers.p4"
+#include "defines.p4"
+
+control table0_control(inout headers_t hdr,
+                       inout local_metadata_t local_metadata,
+                       inout standard_metadata_t standard_metadata) {
+
+    direct_counter(CounterType.packets_and_bytes) table0_counter;
+
+    action set_next_hop_id(next_hop_id_t next_hop_id) {
+        local_metadata.next_hop_id = next_hop_id;
+    }
+
+    table table0 {
+        key = {
+            standard_metadata.ingress_port : ternary;
+            hdr.ethernet.src_addr          : ternary;
+            hdr.ethernet.dst_addr          : ternary;
+            hdr.ethernet.ether_type        : ternary;
+            hdr.ipv4.src_addr              : ternary;
+            hdr.ipv4.dst_addr              : ternary;
+            hdr.ipv4.protocol              : ternary;
+            local_metadata.l4_src_port     : ternary;
+            local_metadata.l4_dst_port     : ternary;
+        }
+        actions = {
+            set_egress_port(standard_metadata);
+            send_to_cpu(standard_metadata);
+            set_next_hop_id();
+            _drop();
+        }
+        const default_action = _drop();
+        counters = table0_counter;
+    }
+
+    apply {
+        table0.apply();
+     }
+}
+
+#endif
\ No newline at end of file
diff --git a/pipelines/basic/src/main/resources/include/wcmp.p4 b/pipelines/basic/src/main/resources/include/wcmp.p4
new file mode 100644
index 0000000..9d6e00f
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/wcmp.p4
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WCMP__
+#define __WCMP__
+
+#include "headers.p4"
+#include "defines.p4"
+
+control wcmp_control(inout headers_t hdr,
+                     inout local_metadata_t local_metadata,
+                     inout standard_metadata_t standard_metadata) {
+
+    direct_counter(CounterType.packets_and_bytes) wcmp_table_counter;
+    action_selector(HashAlgorithm.crc16, 32w64, 32w16) wcmp_selector;
+
+    table wcmp_table {
+        support_timeout = false;
+        key = {
+            local_metadata.next_hop_id : exact;
+            hdr.ipv4.src_addr          : selector;
+            hdr.ipv4.dst_addr          : selector;
+            hdr.ipv4.protocol          : selector;
+            local_metadata.l4_src_port : selector;
+            local_metadata.l4_dst_port : selector;
+        }
+        actions = {
+            set_egress_port(standard_metadata);
+        }
+        implementation = wcmp_selector;
+        counters = wcmp_table_counter;
+    }
+
+    apply {
+        if (local_metadata.next_hop_id != 0) {
+            wcmp_table.apply();
+        }
+    }
+}
+
+#endif
\ No newline at end of file