[SDFAB-102] Backport changes required for policies to fabric.p4

Change-Id: I1c9a66c548b5d5e1d3a92ff29208263fb6844c0c
diff --git a/pipelines/fabric/impl/src/main/resources/include/control/acl.p4 b/pipelines/fabric/impl/src/main/resources/include/control/acl.p4
index 80efa8f..34ef4d1 100644
--- a/pipelines/fabric/impl/src/main/resources/include/control/acl.p4
+++ b/pipelines/fabric/impl/src/main/resources/include/control/acl.p4
@@ -24,6 +24,12 @@
              inout fabric_metadata_t fabric_metadata,
              inout standard_metadata_t standard_metadata) {
 
+    ipv4_addr_t ipv4_src    = 0;
+    ipv4_addr_t ipv4_dst    = 0;
+    bit<8> ip_proto         = 0;
+    l4_port_t l4_sport      = 0;
+    l4_port_t l4_dport      = 0;
+
     /*
      * ACL Table.
      */
@@ -59,18 +65,18 @@
 
     table acl {
         key = {
-            standard_metadata.ingress_port: ternary @name("ig_port"); // 9
-            fabric_metadata.ip_proto: ternary @name("ip_proto"); // 8
-            fabric_metadata.l4_sport: ternary @name("l4_sport"); // 16
-            fabric_metadata.l4_dport: ternary @name("l4_dport"); // 16
-            hdr.ethernet.dst_addr: ternary @name("eth_dst"); // 48
-            hdr.ethernet.src_addr: ternary @name("eth_src"); // 48
-            hdr.vlan_tag.vlan_id: ternary @name("vlan_id"); // 12
-            hdr.eth_type.value: ternary @name("eth_type"); //16
-            hdr.ipv4.src_addr: ternary @name("ipv4_src"); // 32
-            hdr.ipv4.dst_addr: ternary @name("ipv4_dst"); // 32
-            hdr.icmp.icmp_type: ternary @name("icmp_type"); // 8
-            hdr.icmp.icmp_code: ternary @name("icmp_code"); // 8
+            standard_metadata.ingress_port  : ternary @name("ig_port");   // 9
+            hdr.ethernet.dst_addr           : ternary @name("eth_dst");   // 48
+            hdr.ethernet.src_addr           : ternary @name("eth_src");   // 48
+            hdr.vlan_tag.vlan_id            : ternary @name("vlan_id");   // 12
+            hdr.eth_type.value              : ternary @name("eth_type");  // 16
+            ipv4_src                        : ternary @name("ipv4_src");  // 32
+            ipv4_dst                        : ternary @name("ipv4_dst");  // 32
+            ip_proto                        : ternary @name("ip_proto");  // 8
+            hdr.icmp.icmp_type              : ternary @name("icmp_type"); // 8
+            hdr.icmp.icmp_code              : ternary @name("icmp_code"); // 8
+            l4_sport                        : ternary @name("l4_sport");  // 16
+            l4_dport                        : ternary @name("l4_dport");  // 16
         }
 
         actions = {
@@ -87,6 +93,29 @@
     }
 
     apply {
+        if (hdr.gtpu.isValid() && hdr.inner_ipv4.isValid()) {
+            ipv4_src = hdr.inner_ipv4.src_addr;
+            ipv4_dst = hdr.inner_ipv4.dst_addr;
+            ip_proto = hdr.inner_ipv4.protocol;
+            if (hdr.inner_tcp.isValid()) {
+                l4_sport = hdr.inner_tcp.sport;
+                l4_dport = hdr.inner_tcp.dport;
+            } else if (hdr.inner_udp.isValid()) {
+                l4_sport = hdr.inner_udp.sport;
+                l4_dport = hdr.inner_udp.dport;
+            }
+        } else if (hdr.ipv4.isValid()) {
+            ipv4_src = hdr.ipv4.src_addr;
+            ipv4_dst = hdr.ipv4.dst_addr;
+            ip_proto = hdr.ipv4.protocol;
+            if (hdr.tcp.isValid()) {
+                l4_sport = hdr.tcp.sport;
+                l4_dport = hdr.tcp.dport;
+            } else if (hdr.udp.isValid()) {
+                l4_sport = hdr.udp.sport;
+                l4_dport = hdr.udp.dport;
+            }
+        }
         acl.apply();
     }
 }
diff --git a/pipelines/fabric/impl/src/main/resources/include/header.p4 b/pipelines/fabric/impl/src/main/resources/include/header.p4
index 4b4e315..6b47a60 100644
--- a/pipelines/fabric/impl/src/main/resources/include/header.p4
+++ b/pipelines/fabric/impl/src/main/resources/include/header.p4
@@ -227,12 +227,12 @@
     ipv4_t gtpu_ipv4;
     udp_t gtpu_udp;
     gtpu_t outer_gtpu;
+#endif // WITH_SPGW
     gtpu_t gtpu;
     ipv4_t inner_ipv4;
     udp_t inner_udp;
     tcp_t inner_tcp;
     icmp_t inner_icmp;
-#endif // WITH_SPGW
     ipv4_t ipv4;
 #ifdef WITH_IPV6
     ipv6_t ipv6;
diff --git a/pipelines/fabric/impl/src/main/resources/include/parser.p4 b/pipelines/fabric/impl/src/main/resources/include/parser.p4
index 5e5ee5b..699f32b 100644
--- a/pipelines/fabric/impl/src/main/resources/include/parser.p4
+++ b/pipelines/fabric/impl/src/main/resources/include/parser.p4
@@ -183,10 +183,8 @@
         fabric_metadata.l4_dport = hdr.udp.dport;
         gtpu_t gtpu = packet.lookahead<gtpu_t>();
         transition select(hdr.udp.dport, gtpu.version, gtpu.msgtype) {
-#ifdef WITH_SPGW
-            // Treat GTP control traffic as payload.
-            (UDP_PORT_GTPU, GTP_V1, GTP_GPDU): parse_gtpu;
-#endif // WITH_SPGW
+        // Treat GTP control traffic as payload.
+        (UDP_PORT_GTPU, GTP_V1, GTP_GPDU): parse_gtpu;
 #ifdef WITH_INT
             default: parse_int;
 #else
@@ -200,7 +198,6 @@
         transition accept;
     }
 
-#ifdef WITH_SPGW
     state parse_gtpu {
         packet.extract(hdr.gtpu);
         transition parse_inner_ipv4;
@@ -219,8 +216,10 @@
 
     state parse_inner_udp {
         packet.extract(hdr.inner_udp);
+#ifdef WITH_SPGW
         fabric_metadata.inner_l4_sport = hdr.inner_udp.sport;
         fabric_metadata.inner_l4_dport = hdr.inner_udp.dport;
+#endif // WITH_SPGW
 #ifdef WITH_INT
         transition parse_int;
 #else
@@ -228,18 +227,19 @@
 #endif // WITH_INT
     }
 
-        state parse_inner_tcp {
+    state parse_inner_tcp {
         packet.extract(hdr.inner_tcp);
+#ifdef WITH_SPGW
         fabric_metadata.inner_l4_sport = hdr.inner_tcp.sport;
         fabric_metadata.inner_l4_dport = hdr.inner_tcp.dport;
+#endif // WITH_SPGW
         transition accept;
     }
 
-        state parse_inner_icmp {
+    state parse_inner_icmp {
         packet.extract(hdr.inner_icmp);
         transition accept;
     }
-#endif // WITH_SPGW
 
 #ifdef WITH_INT
     state parse_int {
@@ -315,14 +315,12 @@
         packet.emit(hdr.tcp);
         packet.emit(hdr.udp);
         packet.emit(hdr.icmp);
-#ifdef WITH_SPGW
         // if we parsed a GTPU packet but did not decap it
         packet.emit(hdr.gtpu);
         packet.emit(hdr.inner_ipv4);
         packet.emit(hdr.inner_tcp);
         packet.emit(hdr.inner_udp);
         packet.emit(hdr.inner_icmp);
-#endif // WITH_SPGW
 #ifdef WITH_INT
         packet.emit(hdr.intl4_shim);
         packet.emit(hdr.int_header);