[ONOS-7154] Initial INT pipeline implementation

Change-Id: I85829350349c77abfcb14445de290be599573fea
diff --git a/pipelines/basic/src/main/resources/include/int_source.p4 b/pipelines/basic/src/main/resources/include/int_source.p4
new file mode 100644
index 0000000..a09309f
--- /dev/null
+++ b/pipelines/basic/src/main/resources/include/int_source.p4
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+
+/* -*- P4_16 -*- */
+#ifndef __INT_SOURCE__
+#define __INT_SOURCE__
+
+// Insert INT header to the packet
+control process_int_source (
+    inout headers_t hdr,
+    inout local_metadata_t local_metadata,
+    inout standard_metadata_t standard_metadata) {
+
+    direct_counter(CounterType.packets_and_bytes) counter_int_source;
+
+    action int_source(bit<8> max_hop, bit<5> ins_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) {
+        // insert INT shim header
+        hdr.intl4_shim.setValid();
+        // int_type: Hop-by-hop type (1) , destination type (2)
+        hdr.intl4_shim.int_type = 1;
+        hdr.intl4_shim.len = INT_HEADER_LEN_WORD;
+
+        // insert INT header
+        hdr.int_header.setValid();
+        hdr.int_header.ver = 0;
+        hdr.int_header.rep = 0;
+        hdr.int_header.c = 0;
+        hdr.int_header.e = 0;
+        hdr.int_header.rsvd1 = 0;
+        hdr.int_header.ins_cnt = ins_cnt;
+        hdr.int_header.max_hop_cnt = max_hop;
+        hdr.int_header.total_hop_cnt = 0;
+        hdr.int_header.instruction_mask_0003 = ins_mask0003;
+        hdr.int_header.instruction_mask_0407 = ins_mask0407;
+        hdr.int_header.instruction_mask_0811 = 0; // not supported
+        hdr.int_header.instruction_mask_1215 = 0; // not supported
+
+        // insert INT tail header
+        hdr.intl4_tail.setValid();
+        hdr.intl4_tail.next_proto = hdr.ipv4.protocol;
+        hdr.intl4_tail.dest_port = local_metadata.l4_dst_port;
+        hdr.intl4_tail.dscp = 0; // not used
+
+        hdr.udp.dst_port = INT_PORT;
+
+        // add the header len (8 bytes) to total len
+        hdr.ipv4.len = hdr.ipv4.len + 16;
+        hdr.udp.length_ = hdr.udp.length_ + 16;
+    }
+
+    table tb_int_source {
+        key = {
+            local_metadata.int_meta.sink: exact;
+            local_metadata.int_meta.source: exact;
+            hdr.ipv4.src_addr: ternary;
+            hdr.ipv4.dst_addr: ternary;
+            local_metadata.l4_src_port: ternary;
+            local_metadata.l4_dst_port: ternary;
+        }
+        actions = {
+            int_source; // sink = 0 & source = 1
+        }
+        counters = counter_int_source;
+        size = 1024;
+    }
+
+    apply {
+        tb_int_source.apply();
+    }
+}
+
+control process_set_source_sink (
+    inout headers_t hdr,
+    inout local_metadata_t local_metadata,
+    inout standard_metadata_t standard_metadata) {
+
+    direct_counter(CounterType.packets_and_bytes) counter_set_source;
+    direct_counter(CounterType.packets_and_bytes) counter_set_sink;
+
+    action int_set_source () {
+        local_metadata.int_meta.source =  1;
+    }
+
+    action int_set_sink () {
+        local_metadata.int_meta.sink = 1;
+    }
+
+    table tb_set_source {
+        key = {
+            hdr.ipv4.src_addr: ternary;
+            hdr.ipv4.dst_addr: ternary;
+            local_metadata.l4_src_port: ternary;
+            local_metadata.l4_dst_port: ternary;
+        }
+        actions = {
+            int_set_source;
+        }
+        counters = counter_set_source;
+        size = 1024;
+    }
+
+    table tb_set_sink {
+        key = {
+            hdr.ipv4.src_addr: ternary;
+            hdr.ipv4.dst_addr: ternary;
+            local_metadata.l4_src_port: ternary;
+            local_metadata.l4_dst_port: ternary;
+        }
+        actions = {
+            int_set_sink;
+        }
+        counters = counter_set_sink;
+        size = 1024;
+    }
+
+    apply {
+        if (hdr.udp.isValid()) {
+            tb_set_source.apply();
+            tb_set_sink.apply();
+        }
+    }
+}
+#endif