INT transit for tofino (only with spgw enabled)

Because of recent update in p4c that uses different names for
P4 entities, requires manual search/replace in p4info/context.json

Change-Id: If7d6ea738710ef0c8786d9ff07f21f240fb6cedc
diff --git a/pipelines/fabric/src/main/resources/include/parser.p4 b/pipelines/fabric/src/main/resources/include/parser.p4
index 8b03da1..2920a15 100644
--- a/pipelines/fabric/src/main/resources/include/parser.p4
+++ b/pipelines/fabric/src/main/resources/include/parser.p4
@@ -25,6 +25,8 @@
 inout fabric_metadata_t fabric_metadata,
 inout standard_metadata_t standard_metadata) {
 
+    bit<6> last_ipv4_dscp = 0;
+
     state start {
         transition select(standard_metadata.ingress_port) {
             CPU_PORT: parse_packet_out;
@@ -82,6 +84,7 @@
 
     state parse_ipv4 {
         packet.extract(hdr.ipv4);
+        last_ipv4_dscp = hdr.ipv4.dscp;
         fabric_metadata.ip_proto = hdr.ipv4.protocol;
         //Need header verification?
         transition select(hdr.ipv4.protocol) {
@@ -121,14 +124,16 @@
         packet.extract(hdr.udp);
         fabric_metadata.l4_src_port = hdr.udp.src_port;
         fabric_metadata.l4_dst_port = hdr.udp.dst_port;
-#ifdef WITH_SPGW
         transition select(hdr.udp.dst_port) {
+#ifdef WITH_SPGW
             UDP_PORT_GTPU: parse_gtpu;
-            default: accept;
-        }
-#else
-        transition accept;
 #endif // WITH_SPGW
+#ifdef WITH_INT_TRANSIT
+            default: parse_int;
+#else
+            default: accept;
+#endif // WITH_INT_TRANSIT
+        }
     }
 
     state parse_icmp {
@@ -144,6 +149,7 @@
 
     state parse_ipv4_inner {
         packet.extract(hdr.gtpu_ipv4);
+        last_ipv4_dscp = hdr.gtpu_ipv4.dscp;
         transition select(hdr.gtpu_ipv4.protocol) {
             PROTO_TCP: parse_tcp;
             PROTO_UDP: parse_udp_inner;
@@ -156,9 +162,33 @@
         packet.extract(hdr.gtpu_udp);
         fabric_metadata.l4_src_port = hdr.gtpu_udp.src_port;
         fabric_metadata.l4_dst_port = hdr.gtpu_udp.dst_port;
+#ifdef WITH_INT_TRANSIT
+        transition parse_int;
+#else
         transition accept;
+#endif // WITH_INT_TRANSIT
     }
 #endif // WITH_SPGW
+
+#ifdef WITH_INT_TRANSIT
+    state parse_int {
+        transition select(last_ipv4_dscp) {
+            DSCP_INT &&& DSCP_INT: parse_intl4_shim;
+            default: accept;
+        }
+    }
+
+    state parse_intl4_shim {
+        packet.extract(hdr.intl4_shim);
+        transition parse_int_header;
+    }
+
+    state parse_int_header {
+        packet.extract(hdr.int_header);
+        fabric_metadata.int_metadata.ins_cnt_tmp = hdr.int_header.ins_cnt;
+        transition accept;
+    }
+#endif // WITH_INT_TRANSIT
 }
 
 control FabricDeparser(packet_out packet, in parsed_headers_t hdr) {
@@ -180,6 +210,18 @@
         packet.emit(hdr.tcp);
         packet.emit(hdr.udp);
         packet.emit(hdr.icmp);
+#ifdef WITH_INT_TRANSIT
+        packet.emit(hdr.intl4_shim);
+        packet.emit(hdr.int_header);
+        packet.emit(hdr.int_switch_id);
+        packet.emit(hdr.int_port_ids);
+        packet.emit(hdr.int_hop_latency);
+        packet.emit(hdr.int_q_occupancy);
+        packet.emit(hdr.int_ingress_tstamp);
+        packet.emit(hdr.int_egress_tstamp);
+        packet.emit(hdr.int_q_congestion);
+        packet.emit(hdr.int_egress_port_tx_util);
+#endif // WITH_INT_TRANSIT
     }
 }