Support tofino build for P4_14 test programs

Also, modified programs such that both the P4_14 and P4_16 versions
produce the same forwarding behaviour and control API (i.e. P4Info)

Change-Id: I90b7fdfedff5f2a89e0f2295d32e2bb61cd0e0eb
diff --git a/tools/test/p4src/p4-14/Makefile b/tools/test/p4src/p4-14/Makefile
index 6b9618b..623b5d3 100644
--- a/tools/test/p4src/p4-14/Makefile
+++ b/tools/test/p4src/p4-14/Makefile
@@ -1,7 +1,7 @@
 all: default.json empty.json ecmp.json wcmp.json
 
 default.json: default.p4
-	p4c-bm2-ss --p4v 14 -o p4c-out/default.json \
+	p4c-bm2-ss -D DO_BMV2_BUILD --p4v 14 -o p4c-out/default.json \
 	--p4runtime-file p4c-out/default.p4info --p4runtime-format text \
 	default.p4
 
@@ -11,13 +11,13 @@
 	empty.p4
 
 ecmp.json: ecmp.p4
-	p4c-bm2-ss --p4v 14 -o p4c-out/ecmp.json \
+	p4c-bm2-ss -D DO_BMV2_BUILD --p4v 14 -o p4c-out/ecmp.json \
 	--p4runtime-file p4c-out/ecmp.p4info --p4runtime-format text \
 	ecmp.p4
 
 wcmp.json: wcmp.p4
-	p4c-bm2-ss --p4v 14 -o p4c-out/wcmp.json \
-	--p4runtime-file p4c-out/ecmp.p4info --p4runtime-format text \
+	p4c-bm2-ss -D DO_BMV2_BUILD --p4v 14 -o p4c-out/wcmp.json \
+	--p4runtime-file p4c-out/wcmp.p4info --p4runtime-format text \
 	wcmp.p4
 
 clean:
diff --git a/tools/test/p4src/p4-14/default.p4 b/tools/test/p4src/p4-14/default.p4
index be88a5d..f653b98 100644
--- a/tools/test/p4src/p4-14/default.p4
+++ b/tools/test/p4src/p4-14/default.p4
@@ -3,18 +3,19 @@
 #include "include/parser.p4"
 #include "include/actions.p4"
 #include "include/port_counters.p4"
+#include "include/packet_io.p4"
 
 table table0 {
     reads {
-        standard_metadata.ingress_port : ternary;
-        ethernet.dstAddr : ternary;
-        ethernet.srcAddr : ternary;
+        IGR_PORT_FIELD     : ternary;
+        ethernet.dstAddr   : ternary;
+        ethernet.srcAddr   : ternary;
         ethernet.etherType : ternary;
     }
     actions {
         set_egress_port;
         send_to_cpu;
-        drop;
+        _drop;
     }
     support_timeout: true;
 }
@@ -26,6 +27,13 @@
 }
 
 control ingress {
-    apply(table0);
+    ingress_pkt_io();
+    if (not valid(packet_out_hdr)) {
+        apply(table0);
+    }
     process_port_counters();
+}
+
+control egress {
+    egress_pkt_io();
 }
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/ecmp.p4 b/tools/test/p4src/p4-14/ecmp.p4
index f751049..341e1e1 100644
--- a/tools/test/p4src/p4-14/ecmp.p4
+++ b/tools/test/p4src/p4-14/ecmp.p4
@@ -3,12 +3,19 @@
 #include "include/parser.p4"
 #include "include/actions.p4"
 #include "include/port_counters.p4"
+#include "include/packet_io.p4"
+
+/*
+    Expected number of ports of an ECMP group.
+    This value is fixed, .i.e. we do not support ECMP over port groups of different size.
+    Due to hardware limitations, this value must be constant and a power of 2.
+*/
+#define ECMP_GROUP_SIZE 4
 
 header_type ecmp_metadata_t {
     fields {
         groupId : 16;
         selector : 16;
-        groupSize : 32; // Not used. Workaround to avoid p4c complaining about inferring type to groupSize.
     }
 }
 
@@ -32,24 +39,26 @@
     output_width : 32;
 }
 
-action ecmp_group(groupId, groupSize) {
+action ecmp_group(groupId) {
     modify_field(ecmp_metadata.groupId, groupId);
-    modify_field(ecmp_metadata.groupSize, groupSize);
-    modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, groupSize);
+    modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, ECMP_GROUP_SIZE);
 }
 
+#ifdef __TOFINO_BUILD__
+@pragma immediate 0
+#endif
 table table0 {
     reads {
-        standard_metadata.ingress_port : ternary;
-        ethernet.dstAddr : ternary;
-        ethernet.srcAddr : ternary;
+        IGR_PORT_FIELD     : ternary;
+        ethernet.dstAddr   : ternary;
+        ethernet.srcAddr   : ternary;
         ethernet.etherType : ternary;
     }
     actions {
         set_egress_port;
         ecmp_group;
         send_to_cpu;
-        drop;
+        _drop;
     }
     support_timeout: true;
 }
@@ -77,10 +86,17 @@
 }
 
 control ingress {
-    apply(table0) {
-        ecmp_group {
-            apply(ecmp_group_table);
+    ingress_pkt_io();
+    if (not valid(packet_out_hdr)) {
+        apply(table0) {
+            ecmp_group {
+                apply(ecmp_group_table);
+            }
         }
     }
     process_port_counters();
+}
+
+control egress {
+    egress_pkt_io();
 }
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/include/actions.p4 b/tools/test/p4src/p4-14/include/actions.p4
index 8649da0..961890d 100644
--- a/tools/test/p4src/p4-14/include/actions.p4
+++ b/tools/test/p4src/p4-14/include/actions.p4
@@ -1,11 +1,24 @@
+#ifndef __ACTIONS_P4__
+#define __ACTIONS_P4__
+#include "headers.p4"
+
 action set_egress_port(port) {
-    modify_field(standard_metadata.egress_spec, port);
+    modify_field(EGR_PORT_FIELD, port);
 }
 
-action drop() {
+action _drop() {
+    #ifdef __TOFINO_BUILD__
+    drop();
+    #else
     modify_field(standard_metadata.egress_spec, DROP_PORT);
+    #endif
 }
 
 action send_to_cpu() {
+    #ifdef __TOFINO_BUILD__
+    modify_field(ig_intr_md_for_tm.copy_to_cpu, 1);
+    #else
     modify_field(standard_metadata.egress_spec, CPU_PORT);
-}
\ No newline at end of file
+    #endif
+}
+#endif
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/include/defines.p4 b/tools/test/p4src/p4-14/include/defines.p4
index c9229c9..b47a74a 100644
--- a/tools/test/p4src/p4-14/include/defines.p4
+++ b/tools/test/p4src/p4-14/include/defines.p4
@@ -2,3 +2,25 @@
 #define MAX_PORTS 254
 #define CPU_PORT 255
 #define DROP_PORT 511
+
+#define NULL_ETH_TYPE 0x00
+#define ETHERTYPE_IPV4 0x0800
+#define IP_PROTOCOLS_TCP  6
+#define IP_PROTOCOLS_UDP  17
+
+// Build for Tofino by default.
+
+#ifdef DO_BMV2_BUILD
+#define __BMV2_BUILD__ 1
+#else
+#define __TOFINO_BUILD__ 1
+#endif
+
+#ifdef __TOFINO_BUILD__
+#define EGR_PORT_FIELD ig_intr_md_for_tm.ucast_egress_port
+#define IGR_PORT_FIELD ig_intr_md.ingress_port
+
+#else
+#define EGR_PORT_FIELD standard_metadata.egress_spec
+#define IGR_PORT_FIELD standard_metadata.ingress_port
+#endif
diff --git a/tools/test/p4src/p4-14/include/headers.p4 b/tools/test/p4src/p4-14/include/headers.p4
index 57bda87..c8fb31f 100644
--- a/tools/test/p4src/p4-14/include/headers.p4
+++ b/tools/test/p4src/p4-14/include/headers.p4
@@ -1,9 +1,19 @@
-header_type intrinsic_metadata_t {
+#ifndef __HEADERS_P4__
+#define __HEADERS_P4__
+
+#ifdef __TOFINO_BUILD__
+#include <tofino/intrinsic_metadata.p4>
+#endif
+
+header_type packet_in_t {
     fields {
-        ingress_global_timestamp : 32;
-        lf_field_list : 32;
-        mcast_grp : 16;
-        egress_rid : 16;
+        ingress_port: 9;
+    }
+}
+
+header_type packet_out_t {
+    fields {
+        egress_port: 9;
     }
 }
 
@@ -55,4 +65,6 @@
         length_ : 16;
         checksum : 16;
     }
-}
\ No newline at end of file
+}
+
+#endif
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/include/packet_io.p4 b/tools/test/p4src/p4-14/include/packet_io.p4
new file mode 100644
index 0000000..5da7a65
--- /dev/null
+++ b/tools/test/p4src/p4-14/include/packet_io.p4
@@ -0,0 +1,46 @@
+#ifndef __PACKET_IO__
+#define __PACKET_IO__
+#include "headers.p4"
+#include "parser.p4"
+
+action _packet_out() {
+    modify_field(EGR_PORT_FIELD, packet_out_hdr.egress_port);
+    remove_header(packet_out_hdr);
+}
+
+table ingress_pkt {
+    actions {
+        _packet_out;
+    }
+    default_action: _packet_out();
+}
+
+control ingress_pkt_io {
+    if (valid(packet_out_hdr)) {
+        apply(ingress_pkt);
+    }
+}
+
+action add_packet_in_hdr() {
+    add_header(packet_in_hdr);
+    modify_field(packet_in_hdr.ingress_port, IGR_PORT_FIELD);
+}
+
+table egress_pkt {
+    actions {
+        add_packet_in_hdr;
+    }
+    default_action: add_packet_in_hdr();
+}
+
+control egress_pkt_io {
+    #ifdef __TOFINO_BUILD__
+    if (ig_intr_md_for_tm.copy_to_cpu == 1) {
+    #else
+    if (IGR_PORT_FIELD == CPU_PORT) {
+    #endif
+        apply(egress_pkt);
+    }
+}
+
+#endif
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/include/parser.p4 b/tools/test/p4src/p4-14/include/parser.p4
index 6a205ec..73dcdfd 100644
--- a/tools/test/p4src/p4-14/include/parser.p4
+++ b/tools/test/p4src/p4-14/include/parser.p4
@@ -1,12 +1,40 @@
-metadata intrinsic_metadata_t intrinsic_metadata;
+#ifndef __PARSER_P4__
+#define __PARSER_P4__
+#include "defines.p4"
+#include "headers.p4"
+
+header packet_in_t packet_in_hdr;
+header packet_out_t packet_out_hdr;
+header ethernet_t ethernet;
+header ipv4_t ipv4;
+header tcp_t tcp;
+header udp_t udp;
 
 parser start {
+    // FIXME: Cheat the compiler to generate the deparser of packet in
+    // This is just a hack, we assume first 8 bit of etherType won't be 0
+    return select( current(96, 8) ) {
+        NULL_ETH_TYPE : parse_pkt_in;
+        default       : default_parser;
+    }
+}
+
+parser parse_pkt_in {
+    extract(packet_in_hdr);
     return parse_ethernet;
 }
 
-#define ETHERTYPE_IPV4 0x0800
+parser default_parser {
+    return select(IGR_PORT_FIELD) {
+        CPU_PORT : parse_pkt_out;
+        default  : parse_ethernet;
+    }
+}
 
-header ethernet_t ethernet;
+parser parse_pkt_out {
+    extract(packet_out_hdr);
+    return parse_ethernet;
+}
 
 parser parse_ethernet {
     extract(ethernet);
@@ -16,11 +44,6 @@
     }
 }
 
-header ipv4_t ipv4;
-
-#define IP_PROTOCOLS_TCP  6
-#define IP_PROTOCOLS_UDP  17
-
 parser parse_ipv4 {
     extract(ipv4);
     return select(latest.fragOffset, latest.protocol) {
@@ -30,16 +53,14 @@
     }
 }
 
-header tcp_t tcp;
-
 parser parse_tcp {
     extract(tcp);
     return ingress;
 }
 
-header udp_t udp;
-
 parser parse_udp {
     extract(udp);
     return ingress;
-}
\ No newline at end of file
+}
+
+#endif
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/include/port_counters.p4 b/tools/test/p4src/p4-14/include/port_counters.p4
index 06cba4f..44a2b0e 100644
--- a/tools/test/p4src/p4-14/include/port_counters.p4
+++ b/tools/test/p4src/p4-14/include/port_counters.p4
@@ -1,5 +1,9 @@
+#ifndef __PORT_COUNTERS_P4__
+#define __PORT_COUNTERS_P4__
+#include "defines.p4"
+
 counter ingress_port_counter {
-    type : packets; // bmv2 always counts both bytes and packets 
+    type : packets; // bmv2 always counts both bytes and packets
     instance_count : MAX_PORTS;
     min_width : 32;
 }
@@ -10,20 +14,29 @@
     min_width : 32;
 }
 
-table port_count_table {
-    actions {
-        count_packet;
-    }
+action count_ingress() {
+    count(ingress_port_counter, IGR_PORT_FIELD);
 }
 
-action count_packet() {
-    count(ingress_port_counter, standard_metadata.ingress_port);
-    count(egress_port_counter, standard_metadata.egress_spec);
+action count_egress() {
+    count(egress_port_counter, EGR_PORT_FIELD);
+}
+
+table ingress_port_count_table {
+    actions { count_ingress; }
+    default_action: count_ingress;
+}
+
+table egress_port_count_table {
+    actions { count_egress; }
+    default_action: count_egress;
 }
 
 control process_port_counters {
-	// Avoid counting logical ports, such as drop and cpu
-	if (standard_metadata.egress_spec < MAX_PORTS) {
-		apply(port_count_table);
-	}
-}
\ No newline at end of file
+    if (EGR_PORT_FIELD < MAX_PORTS) {
+        apply(ingress_port_count_table);
+        apply(egress_port_count_table);
+    }
+}
+
+#endif
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/p4c-out/default.json b/tools/test/p4src/p4-14/p4c-out/default.json
index 4490c18..347b3be 100644
--- a/tools/test/p4src/p4-14/p4c-out/default.json
+++ b/tools/test/p4src/p4-14/p4c-out/default.json
@@ -9,8 +9,10 @@
       "name" : "scalars_0",
       "id" : 0,
       "fields" : [
-        ["tmp", 32, false],
-        ["tmp_0", 32, false]
+        ["tmp_0", 104, false],
+        ["tmp", 8, false],
+        ["tmp_1", 32, false],
+        ["tmp_2", 32, false]
       ]
     },
     {
@@ -41,9 +43,25 @@
       ]
     },
     {
-      "name" : "tcp_t",
+      "name" : "packet_in_t",
       "id" : 3,
       "fields" : [
+        ["ingress_port", 9, false],
+        ["_padding", 7, false]
+      ]
+    },
+    {
+      "name" : "packet_out_t",
+      "id" : 4,
+      "fields" : [
+        ["egress_port", 9, false],
+        ["_padding_0", 7, false]
+      ]
+    },
+    {
+      "name" : "tcp_t",
+      "id" : 5,
+      "fields" : [
         ["srcPort", 16, false],
         ["dstPort", 16, false],
         ["seqNo", 32, false],
@@ -59,7 +77,7 @@
     },
     {
       "name" : "udp_t",
-      "id" : 4,
+      "id" : 6,
       "fields" : [
         ["srcPort", 16, false],
         ["dstPort", 16, false],
@@ -68,18 +86,8 @@
       ]
     },
     {
-      "name" : "intrinsic_metadata_t",
-      "id" : 5,
-      "fields" : [
-        ["ingress_global_timestamp", 32, false],
-        ["lf_field_list", 32, false],
-        ["mcast_grp", 16, false],
-        ["egress_rid", 16, false]
-      ]
-    },
-    {
       "name" : "standard_metadata",
-      "id" : 6,
+      "id" : 7,
       "fields" : [
         ["ingress_port", 9, false],
         ["egress_spec", 9, false],
@@ -98,7 +106,7 @@
         ["mcast_grp", 16, false],
         ["resubmit_flag", 1, false],
         ["egress_rid", 16, false],
-        ["_padding", 5, false]
+        ["_padding_1", 5, false]
       ]
     }
   ],
@@ -132,25 +140,32 @@
       "pi_omit" : true
     },
     {
-      "name" : "tcp",
+      "name" : "packet_in_hdr",
       "id" : 4,
+      "header_type" : "packet_in_t",
+      "metadata" : false,
+      "pi_omit" : true
+    },
+    {
+      "name" : "packet_out_hdr",
+      "id" : 5,
+      "header_type" : "packet_out_t",
+      "metadata" : false,
+      "pi_omit" : true
+    },
+    {
+      "name" : "tcp",
+      "id" : 6,
       "header_type" : "tcp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "udp",
-      "id" : 5,
+      "id" : 7,
       "header_type" : "udp_t",
       "metadata" : false,
       "pi_omit" : true
-    },
-    {
-      "name" : "intrinsic_metadata",
-      "id" : 6,
-      "header_type" : "intrinsic_metadata_t",
-      "metadata" : true,
-      "pi_omit" : true
     }
   ],
   "header_stacks" : [],
@@ -174,8 +189,31 @@
       "init_state" : "start",
       "parse_states" : [
         {
-          "name" : "parse_ethernet",
+          "name" : "default_parser",
           "id" : 0,
+          "parser_ops" : [],
+          "transitions" : [
+            {
+              "value" : "0x00ff",
+              "mask" : null,
+              "next_state" : "parse_pkt_out"
+            },
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "ingress_port"]
+            }
+          ]
+        },
+        {
+          "name" : "parse_ethernet",
+          "id" : 1,
           "parser_ops" : [
             {
               "parameters" : [
@@ -208,7 +246,7 @@
         },
         {
           "name" : "parse_ipv4",
-          "id" : 1,
+          "id" : 2,
           "parser_ops" : [
             {
               "parameters" : [
@@ -249,8 +287,54 @@
           ]
         },
         {
+          "name" : "parse_pkt_in",
+          "id" : 3,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "regular",
+                  "value" : "packet_in_hdr"
+                }
+              ],
+              "op" : "extract"
+            }
+          ],
+          "transitions" : [
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : []
+        },
+        {
+          "name" : "parse_pkt_out",
+          "id" : 4,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "regular",
+                  "value" : "packet_out_hdr"
+                }
+              ],
+              "op" : "extract"
+            }
+          ],
+          "transitions" : [
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : []
+        },
+        {
           "name" : "parse_tcp",
-          "id" : 2,
+          "id" : 5,
           "parser_ops" : [
             {
               "parameters" : [
@@ -273,7 +357,7 @@
         },
         {
           "name" : "parse_udp",
-          "id" : 3,
+          "id" : 6,
           "parser_ops" : [
             {
               "parameters" : [
@@ -296,16 +380,66 @@
         },
         {
           "name" : "start",
-          "id" : 4,
-          "parser_ops" : [],
+          "id" : 7,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "field",
+                  "value" : ["scalars", "tmp_0"]
+                },
+                {
+                  "type" : "lookahead",
+                  "value" : [0, 104]
+                }
+              ],
+              "op" : "set"
+            },
+            {
+              "parameters" : [
+                {
+                  "type" : "field",
+                  "value" : ["scalars", "tmp"]
+                },
+                {
+                  "type" : "expression",
+                  "value" : {
+                    "type" : "expression",
+                    "value" : {
+                      "op" : "&",
+                      "left" : {
+                        "type" : "field",
+                        "value" : ["scalars", "tmp_0"]
+                      },
+                      "right" : {
+                        "type" : "hexstr",
+                        "value" : "0xff"
+                      }
+                    }
+                  }
+                }
+              ],
+              "op" : "set"
+            }
+          ],
           "transitions" : [
             {
+              "value" : "0x00",
+              "mask" : null,
+              "next_state" : "parse_pkt_in"
+            },
+            {
               "value" : "default",
               "mask" : null,
-              "next_state" : "parse_ethernet"
+              "next_state" : "default_parser"
             }
           ],
-          "transition_key" : []
+          "transition_key" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp"]
+            }
+          ]
         }
       ]
     }
@@ -314,7 +448,7 @@
     {
       "name" : "deparser",
       "id" : 0,
-      "order" : ["ethernet", "ipv4", "udp", "tcp"]
+      "order" : ["packet_out_hdr", "packet_in_hdr", "ethernet", "ipv4", "udp", "tcp"]
     }
   ],
   "meter_arrays" : [],
@@ -343,10 +477,45 @@
   "learn_lists" : [],
   "actions" : [
     {
-      "name" : "NoAction",
+      "name" : "add_packet_in_hdr",
       "id" : 0,
       "runtime_data" : [],
-      "primitives" : []
+      "primitives" : [
+        {
+          "op" : "add_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "packet_in_hdr"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 25,
+            "column" : 4,
+            "source_fragment" : "add_header(packet_in_hdr)"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["packet_in_hdr", "ingress_port"]
+            },
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "ingress_port"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 26,
+            "column" : 4,
+            "source_fragment" : "modify_field(packet_in_hdr.ingress_port, standard_metadata.ingress_port)"
+          }
+        }
+      ]
     },
     {
       "name" : "NoAction",
@@ -378,7 +547,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 1,
+            "line" : 5,
             "column" : 23,
             "source_fragment" : "port) { ..."
           }
@@ -404,7 +573,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 10,
+            "line" : 21,
             "column" : 4,
             "source_fragment" : "modify_field(standard_metadata.egress_spec, 255)"
           }
@@ -412,7 +581,7 @@
       ]
     },
     {
-      "name" : "drop",
+      "name" : "_drop",
       "id" : 4,
       "runtime_data" : [],
       "primitives" : [
@@ -430,7 +599,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 6,
+            "line" : 13,
             "column" : 4,
             "source_fragment" : "modify_field(standard_metadata.egress_spec, 511)"
           }
@@ -438,7 +607,7 @@
       ]
     },
     {
-      "name" : "count_packet",
+      "name" : "_packet_out",
       "id" : 5,
       "runtime_data" : [],
       "primitives" : [
@@ -447,52 +616,48 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "field",
-                    "value" : ["standard_metadata", "ingress_port"]
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
-          "op" : "count",
-          "parameters" : [
-            {
-              "type" : "counter_array",
-              "value" : "ingress_port_counter"
+              "value" : ["standard_metadata", "egress_spec"]
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
+              "value" : ["packet_out_hdr", "egress_port"]
             }
           ],
           "source_info" : {
-            "filename" : "include/port_counters.p4",
-            "line" : 20,
+            "filename" : "include/packet_io.p4",
+            "line" : 7,
             "column" : 4,
-            "source_fragment" : "count(ingress_port_counter, standard_metadata.ingress_port)"
+            "source_fragment" : "modify_field(standard_metadata.egress_spec, packet_out_hdr.egress_port)"
           }
         },
         {
+          "op" : "remove_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "packet_out_hdr"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 8,
+            "column" : 4,
+            "source_fragment" : "remove_header(packet_out_hdr)"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "count_egress",
+      "id" : 6,
+      "runtime_data" : [],
+      "primitives" : [
+        {
           "op" : "assign",
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp_1"]
             },
             {
               "type" : "expression",
@@ -522,31 +687,112 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp_1"]
             }
           ],
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 21,
+            "line" : 22,
             "column" : 4,
             "source_fragment" : "count(egress_port_counter, standard_metadata.egress_spec)"
           }
         }
       ]
+    },
+    {
+      "name" : "count_ingress",
+      "id" : 7,
+      "runtime_data" : [],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_2"]
+            },
+            {
+              "type" : "expression",
+              "value" : {
+                "type" : "expression",
+                "value" : {
+                  "op" : "&",
+                  "left" : {
+                    "type" : "field",
+                    "value" : ["standard_metadata", "ingress_port"]
+                  },
+                  "right" : {
+                    "type" : "hexstr",
+                    "value" : "0xffffffff"
+                  }
+                }
+              }
+            }
+          ]
+        },
+        {
+          "op" : "count",
+          "parameters" : [
+            {
+              "type" : "counter_array",
+              "value" : "ingress_port_counter"
+            },
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_2"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 18,
+            "column" : 4,
+            "source_fragment" : "count(ingress_port_counter, standard_metadata.ingress_port)"
+          }
+        }
+      ]
     }
   ],
   "pipelines" : [
     {
       "name" : "ingress",
       "id" : 0,
-      "init_table" : "table0",
+      "init_table" : "node_2",
       "tables" : [
         {
-          "name" : "table0",
+          "name" : "ingress_pkt",
           "id" : 0,
           "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 11,
+            "column" : 0,
+            "source_fragment" : "table ingress_pkt { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [5],
+          "actions" : ["_packet_out"],
+          "base_default_next" : "node_4",
+          "next_tables" : {
+            "_packet_out" : "node_4"
+          },
+          "default_entry" : {
+            "action_id" : 5,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        },
+        {
+          "name" : "table0",
+          "id" : 1,
+          "source_info" : {
             "filename" : "default.p4",
-            "line" : 7,
+            "line" : 8,
             "column" : 0,
             "source_fragment" : "table table0 { ..."
           },
@@ -578,30 +824,30 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [2, 3, 4, 0],
-          "actions" : ["set_egress_port", "send_to_cpu", "drop", "NoAction"],
-          "base_default_next" : "node_3",
+          "action_ids" : [2, 3, 4, 1],
+          "actions" : ["set_egress_port", "send_to_cpu", "_drop", "NoAction"],
+          "base_default_next" : "node_6",
           "next_tables" : {
-            "set_egress_port" : "node_3",
-            "send_to_cpu" : "node_3",
-            "drop" : "node_3",
-            "NoAction" : "node_3"
+            "set_egress_port" : "node_6",
+            "send_to_cpu" : "node_6",
+            "_drop" : "node_6",
+            "NoAction" : "node_6"
           },
           "default_entry" : {
-            "action_id" : 0,
+            "action_id" : 1,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
           }
         },
         {
-          "name" : "port_count_table",
-          "id" : 1,
+          "name" : "ingress_port_count_table",
+          "id" : 2,
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 13,
+            "line" : 25,
             "column" : 0,
-            "source_fragment" : "table port_count_table { ..."
+            "source_fragment" : "table ingress_port_count_table { ..."
           },
           "key" : [],
           "match_type" : "exact",
@@ -610,15 +856,43 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [5, 1],
-          "actions" : ["count_packet", "NoAction"],
-          "base_default_next" : null,
+          "action_ids" : [7],
+          "actions" : ["count_ingress"],
+          "base_default_next" : "egress_port_count_table",
           "next_tables" : {
-            "count_packet" : null,
-            "NoAction" : null
+            "count_ingress" : "egress_port_count_table"
           },
           "default_entry" : {
-            "action_id" : 1,
+            "action_id" : 7,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        },
+        {
+          "name" : "egress_port_count_table",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 30,
+            "column" : 0,
+            "source_fragment" : "table egress_port_count_table { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [6],
+          "actions" : ["count_egress"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "count_egress" : null
+          },
+          "default_entry" : {
+            "action_id" : 6,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -628,12 +902,64 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_3",
+          "name" : "node_2",
           "id" : 0,
           "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 19,
+            "column" : 8,
+            "source_fragment" : "valid(packet_out_hdr)"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "==",
+              "left" : {
+                "type" : "field",
+                "value" : ["packet_out_hdr", "$valid$"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x01"
+              }
+            }
+          },
+          "true_next" : "ingress_pkt",
+          "false_next" : "node_4"
+        },
+        {
+          "name" : "node_4",
+          "id" : 1,
+          "source_info" : {
+            "filename" : "default.p4",
+            "line" : 31,
+            "column" : 12,
+            "source_fragment" : "valid(packet_out_hdr)"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "!=",
+              "left" : {
+                "type" : "field",
+                "value" : ["packet_out_hdr", "$valid$"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x01"
+              }
+            }
+          },
+          "true_next" : "table0",
+          "false_next" : "node_6"
+        },
+        {
+          "name" : "node_6",
+          "id" : 2,
+          "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 26,
-            "column" : 35,
+            "line" : 36,
+            "column" : 38,
             "source_fragment" : "<"
           },
           "expression" : {
@@ -651,17 +977,74 @@
             }
           },
           "false_next" : null,
-          "true_next" : "port_count_table"
+          "true_next" : "ingress_port_count_table"
         }
       ]
     },
     {
       "name" : "egress",
       "id" : 1,
-      "init_table" : null,
-      "tables" : [],
+      "init_table" : "node_11",
+      "tables" : [
+        {
+          "name" : "egress_pkt",
+          "id" : 4,
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 29,
+            "column" : 0,
+            "source_fragment" : "table egress_pkt { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [0],
+          "actions" : ["add_packet_in_hdr"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "add_packet_in_hdr" : null
+          },
+          "default_entry" : {
+            "action_id" : 0,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        }
+      ],
       "action_profiles" : [],
-      "conditionals" : []
+      "conditionals" : [
+        {
+          "name" : "node_11",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 40,
+            "column" : 39,
+            "source_fragment" : "=="
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "==",
+              "left" : {
+                "type" : "field",
+                "value" : ["standard_metadata", "ingress_port"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x00ff"
+              }
+            }
+          },
+          "false_next" : null,
+          "true_next" : "egress_pkt"
+        }
+      ]
     }
   ],
   "checksums" : [],
diff --git a/tools/test/p4src/p4-14/p4c-out/default.p4info b/tools/test/p4src/p4-14/p4c-out/default.p4info
index 40722aa..c076ebb 100644
--- a/tools/test/p4src/p4-14/p4c-out/default.p4info
+++ b/tools/test/p4src/p4-14/p4c-out/default.p4info
@@ -35,7 +35,7 @@
     id: 16829080
   }
   action_refs {
-    id: 16793508
+    id: 16784184
   }
   action_refs {
     id: 16800567
@@ -47,16 +47,45 @@
 }
 tables {
   preamble {
-    id: 33583368
-    name: "port_count_table"
-    alias: "port_count_table"
+    id: 33560548
+    name: "ingress_pkt"
+    alias: "ingress_pkt"
   }
   action_refs {
-    id: 16781545
+    id: 16835928
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33618793
+    name: "egress_port_count_table"
+    alias: "egress_port_count_table"
   }
   action_refs {
-    id: 16800567
-    annotations: "@defaultonly()"
+    id: 16822771
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33579767
+    name: "ingress_port_count_table"
+    alias: "ingress_port_count_table"
+  }
+  action_refs {
+    id: 16837943
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33608529
+    name: "egress_pkt"
+    alias: "egress_pkt"
+  }
+  action_refs {
+    id: 16835663
   }
   size: 1024
 }
@@ -88,16 +117,37 @@
 }
 actions {
   preamble {
-    id: 16793508
-    name: "drop"
-    alias: "drop"
+    id: 16784184
+    name: "_drop"
+    alias: "_drop"
   }
 }
 actions {
   preamble {
-    id: 16781545
-    name: "count_packet"
-    alias: "count_packet"
+    id: 16835928
+    name: "_packet_out"
+    alias: "_packet_out"
+  }
+}
+actions {
+  preamble {
+    id: 16822771
+    name: "count_egress"
+    alias: "count_egress"
+  }
+}
+actions {
+  preamble {
+    id: 16837943
+    name: "count_ingress"
+    alias: "count_ingress"
+  }
+}
+actions {
+  preamble {
+    id: 16835663
+    name: "add_packet_in_hdr"
+    alias: "add_packet_in_hdr"
   }
 }
 counters {
@@ -135,3 +185,28 @@
   }
   direct_table_id: 33617813
 }
+# Manually adding controller_packet_metadata for packet I/O since P4_14 doesn't support annotations.
+controller_packet_metadata {
+  preamble {
+    id: 2868941301
+    name: "packet_in"
+    annotations: "@controller_header(\"packet_in\")"
+  }
+  metadata {
+    id: 1
+    name: "ingress_port"
+    bitwidth: 9
+  }
+}
+controller_packet_metadata {
+  preamble {
+    id: 2868916615
+    name: "packet_out"
+    annotations: "@controller_header(\"packet_out\")"
+  }
+  metadata {
+    id: 1
+    name: "egress_port"
+    bitwidth: 9
+  }
+}
\ No newline at end of file
diff --git a/tools/test/p4src/p4-14/p4c-out/ecmp.json b/tools/test/p4src/p4-14/p4c-out/ecmp.json
index 5de22a5..8c971bb 100644
--- a/tools/test/p4src/p4-14/p4c-out/ecmp.json
+++ b/tools/test/p4src/p4-14/p4c-out/ecmp.json
@@ -9,9 +9,10 @@
       "name" : "scalars_0",
       "id" : 0,
       "fields" : [
-        ["tmp", 64, false],
-        ["tmp_0", 32, false],
-        ["tmp_1", 32, false]
+        ["tmp_0", 104, false],
+        ["tmp", 8, false],
+        ["tmp_1", 32, false],
+        ["tmp_2", 32, false]
       ]
     },
     {
@@ -42,9 +43,25 @@
       ]
     },
     {
-      "name" : "tcp_t",
+      "name" : "packet_in_t",
       "id" : 3,
       "fields" : [
+        ["ingress_port", 9, false],
+        ["_padding", 7, false]
+      ]
+    },
+    {
+      "name" : "packet_out_t",
+      "id" : 4,
+      "fields" : [
+        ["egress_port", 9, false],
+        ["_padding_0", 7, false]
+      ]
+    },
+    {
+      "name" : "tcp_t",
+      "id" : 5,
+      "fields" : [
         ["srcPort", 16, false],
         ["dstPort", 16, false],
         ["seqNo", 32, false],
@@ -60,7 +77,7 @@
     },
     {
       "name" : "udp_t",
-      "id" : 4,
+      "id" : 6,
       "fields" : [
         ["srcPort", 16, false],
         ["dstPort", 16, false],
@@ -70,26 +87,15 @@
     },
     {
       "name" : "ecmp_metadata_t",
-      "id" : 5,
+      "id" : 7,
       "fields" : [
         ["groupId", 16, false],
-        ["selector", 16, false],
-        ["groupSize", 32, false]
-      ]
-    },
-    {
-      "name" : "intrinsic_metadata_t",
-      "id" : 6,
-      "fields" : [
-        ["ingress_global_timestamp", 32, false],
-        ["lf_field_list", 32, false],
-        ["mcast_grp", 16, false],
-        ["egress_rid", 16, false]
+        ["selector", 16, false]
       ]
     },
     {
       "name" : "standard_metadata",
-      "id" : 7,
+      "id" : 8,
       "fields" : [
         ["ingress_port", 9, false],
         ["egress_spec", 9, false],
@@ -108,7 +114,7 @@
         ["mcast_grp", 16, false],
         ["resubmit_flag", 1, false],
         ["egress_rid", 16, false],
-        ["_padding", 5, false]
+        ["_padding_1", 5, false]
       ]
     }
   ],
@@ -142,32 +148,39 @@
       "pi_omit" : true
     },
     {
-      "name" : "tcp",
+      "name" : "packet_in_hdr",
       "id" : 4,
+      "header_type" : "packet_in_t",
+      "metadata" : false,
+      "pi_omit" : true
+    },
+    {
+      "name" : "packet_out_hdr",
+      "id" : 5,
+      "header_type" : "packet_out_t",
+      "metadata" : false,
+      "pi_omit" : true
+    },
+    {
+      "name" : "tcp",
+      "id" : 6,
       "header_type" : "tcp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "udp",
-      "id" : 5,
+      "id" : 7,
       "header_type" : "udp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "ecmp_metadata",
-      "id" : 6,
+      "id" : 8,
       "header_type" : "ecmp_metadata_t",
       "metadata" : true,
       "pi_omit" : true
-    },
-    {
-      "name" : "intrinsic_metadata",
-      "id" : 7,
-      "header_type" : "intrinsic_metadata_t",
-      "metadata" : true,
-      "pi_omit" : true
     }
   ],
   "header_stacks" : [],
@@ -191,8 +204,31 @@
       "init_state" : "start",
       "parse_states" : [
         {
-          "name" : "parse_ethernet",
+          "name" : "default_parser",
           "id" : 0,
+          "parser_ops" : [],
+          "transitions" : [
+            {
+              "value" : "0x00ff",
+              "mask" : null,
+              "next_state" : "parse_pkt_out"
+            },
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "ingress_port"]
+            }
+          ]
+        },
+        {
+          "name" : "parse_ethernet",
+          "id" : 1,
           "parser_ops" : [
             {
               "parameters" : [
@@ -225,7 +261,7 @@
         },
         {
           "name" : "parse_ipv4",
-          "id" : 1,
+          "id" : 2,
           "parser_ops" : [
             {
               "parameters" : [
@@ -266,8 +302,54 @@
           ]
         },
         {
+          "name" : "parse_pkt_in",
+          "id" : 3,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "regular",
+                  "value" : "packet_in_hdr"
+                }
+              ],
+              "op" : "extract"
+            }
+          ],
+          "transitions" : [
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : []
+        },
+        {
+          "name" : "parse_pkt_out",
+          "id" : 4,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "regular",
+                  "value" : "packet_out_hdr"
+                }
+              ],
+              "op" : "extract"
+            }
+          ],
+          "transitions" : [
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : []
+        },
+        {
           "name" : "parse_tcp",
-          "id" : 2,
+          "id" : 5,
           "parser_ops" : [
             {
               "parameters" : [
@@ -290,7 +372,7 @@
         },
         {
           "name" : "parse_udp",
-          "id" : 3,
+          "id" : 6,
           "parser_ops" : [
             {
               "parameters" : [
@@ -313,16 +395,66 @@
         },
         {
           "name" : "start",
-          "id" : 4,
-          "parser_ops" : [],
+          "id" : 7,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "field",
+                  "value" : ["scalars", "tmp_0"]
+                },
+                {
+                  "type" : "lookahead",
+                  "value" : [0, 104]
+                }
+              ],
+              "op" : "set"
+            },
+            {
+              "parameters" : [
+                {
+                  "type" : "field",
+                  "value" : ["scalars", "tmp"]
+                },
+                {
+                  "type" : "expression",
+                  "value" : {
+                    "type" : "expression",
+                    "value" : {
+                      "op" : "&",
+                      "left" : {
+                        "type" : "field",
+                        "value" : ["scalars", "tmp_0"]
+                      },
+                      "right" : {
+                        "type" : "hexstr",
+                        "value" : "0xff"
+                      }
+                    }
+                  }
+                }
+              ],
+              "op" : "set"
+            }
+          ],
           "transitions" : [
             {
+              "value" : "0x00",
+              "mask" : null,
+              "next_state" : "parse_pkt_in"
+            },
+            {
               "value" : "default",
               "mask" : null,
-              "next_state" : "parse_ethernet"
+              "next_state" : "default_parser"
             }
           ],
-          "transition_key" : []
+          "transition_key" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp"]
+            }
+          ]
         }
       ]
     }
@@ -331,7 +463,7 @@
     {
       "name" : "deparser",
       "id" : 0,
-      "order" : ["ethernet", "ipv4", "udp", "tcp"]
+      "order" : ["packet_out_hdr", "packet_in_hdr", "ethernet", "ipv4", "udp", "tcp"]
     }
   ],
   "meter_arrays" : [],
@@ -402,10 +534,45 @@
   "learn_lists" : [],
   "actions" : [
     {
-      "name" : "NoAction",
+      "name" : "add_packet_in_hdr",
       "id" : 0,
       "runtime_data" : [],
-      "primitives" : []
+      "primitives" : [
+        {
+          "op" : "add_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "packet_in_hdr"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 25,
+            "column" : 4,
+            "source_fragment" : "add_header(packet_in_hdr)"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["packet_in_hdr", "ingress_port"]
+            },
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "ingress_port"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 26,
+            "column" : 4,
+            "source_fragment" : "modify_field(packet_in_hdr.ingress_port, standard_metadata.ingress_port)"
+          }
+        }
+      ]
     },
     {
       "name" : "NoAction",
@@ -443,7 +610,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 1,
+            "line" : 5,
             "column" : 23,
             "source_fragment" : "port) { ..."
           }
@@ -474,7 +641,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 1,
+            "line" : 5,
             "column" : 23,
             "source_fragment" : "port) { ..."
           }
@@ -488,10 +655,6 @@
         {
           "name" : "groupId",
           "bitwidth" : 16
-        },
-        {
-          "name" : "groupSize",
-          "bitwidth" : 32
         }
       ],
       "primitives" : [
@@ -509,57 +672,12 @@
           ],
           "source_info" : {
             "filename" : "ecmp.p4",
-            "line" : 35,
+            "line" : 42,
             "column" : 18,
-            "source_fragment" : "groupId, groupSize) { ..."
+            "source_fragment" : "groupId) { ..."
           }
         },
         {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ecmp_metadata", "groupSize"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 1
-            }
-          ],
-          "source_info" : {
-            "filename" : "ecmp.p4",
-            "line" : 35,
-            "column" : 27,
-            "source_fragment" : "groupSize) { ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "local",
-                    "value" : 1
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffffffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
           "op" : "modify_field_with_hash_based_offset",
           "parameters" : [
             {
@@ -575,15 +693,15 @@
               "value" : "calc"
             },
             {
-              "type" : "field",
-              "value" : ["scalars", "tmp"]
+              "type" : "hexstr",
+              "value" : "0x0000000000000004"
             }
           ],
           "source_info" : {
             "filename" : "ecmp.p4",
-            "line" : 38,
+            "line" : 44,
             "column" : 4,
-            "source_fragment" : "modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, groupSize)"
+            "source_fragment" : "modify_field_with_hash_based_offset(ecmp_metadata.selector, 0, ecmp_hash, 4)"
           }
         }
       ]
@@ -607,7 +725,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 10,
+            "line" : 21,
             "column" : 4,
             "source_fragment" : "modify_field(standard_metadata.egress_spec, 255)"
           }
@@ -615,7 +733,7 @@
       ]
     },
     {
-      "name" : "drop",
+      "name" : "_drop",
       "id" : 7,
       "runtime_data" : [],
       "primitives" : [
@@ -633,7 +751,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 6,
+            "line" : 13,
             "column" : 4,
             "source_fragment" : "modify_field(standard_metadata.egress_spec, 511)"
           }
@@ -641,7 +759,7 @@
       ]
     },
     {
-      "name" : "count_packet",
+      "name" : "_packet_out",
       "id" : 8,
       "runtime_data" : [],
       "primitives" : [
@@ -650,47 +768,43 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "field",
-                    "value" : ["standard_metadata", "ingress_port"]
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
-          "op" : "count",
-          "parameters" : [
-            {
-              "type" : "counter_array",
-              "value" : "ingress_port_counter"
+              "value" : ["standard_metadata", "egress_spec"]
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["packet_out_hdr", "egress_port"]
             }
           ],
           "source_info" : {
-            "filename" : "include/port_counters.p4",
-            "line" : 20,
+            "filename" : "include/packet_io.p4",
+            "line" : 7,
             "column" : 4,
-            "source_fragment" : "count(ingress_port_counter, standard_metadata.ingress_port)"
+            "source_fragment" : "modify_field(standard_metadata.egress_spec, packet_out_hdr.egress_port)"
           }
         },
         {
+          "op" : "remove_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "packet_out_hdr"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 8,
+            "column" : 4,
+            "source_fragment" : "remove_header(packet_out_hdr)"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "count_egress",
+      "id" : 9,
+      "runtime_data" : [],
+      "primitives" : [
+        {
           "op" : "assign",
           "parameters" : [
             {
@@ -730,26 +844,107 @@
           ],
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 21,
+            "line" : 22,
             "column" : 4,
             "source_fragment" : "count(egress_port_counter, standard_metadata.egress_spec)"
           }
         }
       ]
+    },
+    {
+      "name" : "count_ingress",
+      "id" : 10,
+      "runtime_data" : [],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_2"]
+            },
+            {
+              "type" : "expression",
+              "value" : {
+                "type" : "expression",
+                "value" : {
+                  "op" : "&",
+                  "left" : {
+                    "type" : "field",
+                    "value" : ["standard_metadata", "ingress_port"]
+                  },
+                  "right" : {
+                    "type" : "hexstr",
+                    "value" : "0xffffffff"
+                  }
+                }
+              }
+            }
+          ]
+        },
+        {
+          "op" : "count",
+          "parameters" : [
+            {
+              "type" : "counter_array",
+              "value" : "ingress_port_counter"
+            },
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_2"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 18,
+            "column" : 4,
+            "source_fragment" : "count(ingress_port_counter, standard_metadata.ingress_port)"
+          }
+        }
+      ]
     }
   ],
   "pipelines" : [
     {
       "name" : "ingress",
       "id" : 0,
-      "init_table" : "table0",
+      "init_table" : "node_2",
       "tables" : [
         {
-          "name" : "table0",
+          "name" : "ingress_pkt",
           "id" : 0,
           "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 11,
+            "column" : 0,
+            "source_fragment" : "table ingress_pkt { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [8],
+          "actions" : ["_packet_out"],
+          "base_default_next" : "node_4",
+          "next_tables" : {
+            "_packet_out" : "node_4"
+          },
+          "default_entry" : {
+            "action_id" : 8,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        },
+        {
+          "name" : "table0",
+          "id" : 1,
+          "source_info" : {
             "filename" : "ecmp.p4",
-            "line" : 41,
+            "line" : 50,
             "column" : 0,
             "source_fragment" : "table table0 { ..."
           },
@@ -781,18 +976,18 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [4, 5, 6, 7, 1],
-          "actions" : ["set_egress_port", "ecmp_group", "send_to_cpu", "drop", "NoAction"],
-          "base_default_next" : "node_4",
+          "action_ids" : [4, 5, 6, 7, 2],
+          "actions" : ["set_egress_port", "ecmp_group", "send_to_cpu", "_drop", "NoAction"],
+          "base_default_next" : "node_7",
           "next_tables" : {
             "ecmp_group" : "ecmp_group_table",
-            "set_egress_port" : "node_4",
-            "send_to_cpu" : "node_4",
-            "drop" : "node_4",
-            "NoAction" : "node_4"
+            "set_egress_port" : "node_7",
+            "send_to_cpu" : "node_7",
+            "_drop" : "node_7",
+            "NoAction" : "node_7"
           },
           "default_entry" : {
-            "action_id" : 1,
+            "action_id" : 2,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -800,10 +995,10 @@
         },
         {
           "name" : "ecmp_group_table",
-          "id" : 1,
+          "id" : 2,
           "source_info" : {
             "filename" : "ecmp.p4",
-            "line" : 57,
+            "line" : 66,
             "column" : 0,
             "source_fragment" : "table ecmp_group_table { ..."
           },
@@ -825,28 +1020,28 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [3, 0],
+          "action_ids" : [3, 1],
           "actions" : ["set_egress_port", "NoAction"],
-          "base_default_next" : "node_4",
+          "base_default_next" : "node_7",
           "next_tables" : {
-            "set_egress_port" : "node_4",
-            "NoAction" : "node_4"
+            "set_egress_port" : "node_7",
+            "NoAction" : "node_7"
           },
           "default_entry" : {
-            "action_id" : 0,
+            "action_id" : 1,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
           }
         },
         {
-          "name" : "port_count_table",
-          "id" : 2,
+          "name" : "ingress_port_count_table",
+          "id" : 3,
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 13,
+            "line" : 25,
             "column" : 0,
-            "source_fragment" : "table port_count_table { ..."
+            "source_fragment" : "table ingress_port_count_table { ..."
           },
           "key" : [],
           "match_type" : "exact",
@@ -855,15 +1050,43 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [8, 2],
-          "actions" : ["count_packet", "NoAction"],
-          "base_default_next" : null,
+          "action_ids" : [10],
+          "actions" : ["count_ingress"],
+          "base_default_next" : "egress_port_count_table",
           "next_tables" : {
-            "count_packet" : null,
-            "NoAction" : null
+            "count_ingress" : "egress_port_count_table"
           },
           "default_entry" : {
-            "action_id" : 2,
+            "action_id" : 10,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        },
+        {
+          "name" : "egress_port_count_table",
+          "id" : 4,
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 30,
+            "column" : 0,
+            "source_fragment" : "table egress_port_count_table { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [9],
+          "actions" : ["count_egress"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "count_egress" : null
+          },
+          "default_entry" : {
+            "action_id" : 9,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -873,12 +1096,64 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_4",
+          "name" : "node_2",
           "id" : 0,
           "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 19,
+            "column" : 8,
+            "source_fragment" : "valid(packet_out_hdr)"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "==",
+              "left" : {
+                "type" : "field",
+                "value" : ["packet_out_hdr", "$valid$"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x01"
+              }
+            }
+          },
+          "true_next" : "ingress_pkt",
+          "false_next" : "node_4"
+        },
+        {
+          "name" : "node_4",
+          "id" : 1,
+          "source_info" : {
+            "filename" : "ecmp.p4",
+            "line" : 90,
+            "column" : 12,
+            "source_fragment" : "valid(packet_out_hdr)"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "!=",
+              "left" : {
+                "type" : "field",
+                "value" : ["packet_out_hdr", "$valid$"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x01"
+              }
+            }
+          },
+          "true_next" : "table0",
+          "false_next" : "node_7"
+        },
+        {
+          "name" : "node_7",
+          "id" : 2,
+          "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 26,
-            "column" : 35,
+            "line" : 36,
+            "column" : 38,
             "source_fragment" : "<"
           },
           "expression" : {
@@ -896,17 +1171,74 @@
             }
           },
           "false_next" : null,
-          "true_next" : "port_count_table"
+          "true_next" : "ingress_port_count_table"
         }
       ]
     },
     {
       "name" : "egress",
       "id" : 1,
-      "init_table" : null,
-      "tables" : [],
+      "init_table" : "node_12",
+      "tables" : [
+        {
+          "name" : "egress_pkt",
+          "id" : 5,
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 29,
+            "column" : 0,
+            "source_fragment" : "table egress_pkt { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [0],
+          "actions" : ["add_packet_in_hdr"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "add_packet_in_hdr" : null
+          },
+          "default_entry" : {
+            "action_id" : 0,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        }
+      ],
       "action_profiles" : [],
-      "conditionals" : []
+      "conditionals" : [
+        {
+          "name" : "node_12",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 40,
+            "column" : 39,
+            "source_fragment" : "=="
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "==",
+              "left" : {
+                "type" : "field",
+                "value" : ["standard_metadata", "ingress_port"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x00ff"
+              }
+            }
+          },
+          "false_next" : null,
+          "true_next" : "egress_pkt"
+        }
+      ]
     }
   ],
   "checksums" : [],
diff --git a/tools/test/p4src/p4-14/p4c-out/ecmp.p4info b/tools/test/p4src/p4-14/p4c-out/ecmp.p4info
index fdfeff0..0961378 100644
--- a/tools/test/p4src/p4-14/p4c-out/ecmp.p4info
+++ b/tools/test/p4src/p4-14/p4c-out/ecmp.p4info
@@ -1,5 +1,33 @@
 tables {
   preamble {
+    id: 33612022
+    name: "ecmp_group_table"
+    alias: "ecmp_group_table"
+  }
+  match_fields {
+    id: 1
+    name: "ecmp_metadata.groupId"
+    bitwidth: 16
+    match_type: EXACT
+  }
+  match_fields {
+    id: 2
+    name: "ecmp_metadata.selector"
+    bitwidth: 16
+    match_type: EXACT
+  }
+  action_refs {
+    id: 16794308
+  }
+  action_refs {
+    id: 16800567
+    annotations: "@defaultonly()"
+  }
+  direct_resource_ids: 302009688
+  size: 1024
+}
+tables {
+  preamble {
     id: 33617813
     name: "table0"
     alias: "table0"
@@ -32,13 +60,13 @@
     id: 16794308
   }
   action_refs {
-    id: 16791212
+    id: 16830055
   }
   action_refs {
     id: 16829080
   }
   action_refs {
-    id: 16793508
+    id: 16784184
   }
   action_refs {
     id: 16800567
@@ -50,59 +78,45 @@
 }
 tables {
   preamble {
-    id: 33596222
-    name: "wcmp_group_table"
-    alias: "wcmp_group_table"
-  }
-  match_fields {
-    id: 1
-    name: "wcmp_meta.groupId"
-    bitwidth: 16
-    match_type: EXACT
-  }
-  match_fields {
-    id: 2
-    name: "wcmp_meta.selector"
-    bitwidth: 32
-    match_type: LPM
+    id: 33560548
+    name: "ingress_pkt"
+    alias: "ingress_pkt"
   }
   action_refs {
-    id: 16794308
-  }
-  action_refs {
-    id: 16800567
-    annotations: "@defaultonly()"
-  }
-  direct_resource_ids: 302006421
-  size: 1024
-}
-tables {
-  preamble {
-    id: 33613026
-    name: "wcmp_set_selector_table"
-    alias: "wcmp_set_selector_table"
-  }
-  action_refs {
-    id: 16819919
-  }
-  action_refs {
-    id: 16800567
-    annotations: "@defaultonly()"
+    id: 16835928
   }
   size: 1024
 }
 tables {
   preamble {
-    id: 33583368
-    name: "port_count_table"
-    alias: "port_count_table"
+    id: 33618793
+    name: "egress_port_count_table"
+    alias: "egress_port_count_table"
   }
   action_refs {
-    id: 16781545
+    id: 16822771
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33579767
+    name: "ingress_port_count_table"
+    alias: "ingress_port_count_table"
   }
   action_refs {
-    id: 16800567
-    annotations: "@defaultonly()"
+    id: 16837943
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33608529
+    name: "egress_pkt"
+    alias: "egress_pkt"
+  }
+  action_refs {
+    id: 16835663
   }
   size: 1024
 }
@@ -115,13 +129,6 @@
 }
 actions {
   preamble {
-    id: 16819919
-    name: "wcmp_set_selector"
-    alias: "wcmp_set_selector"
-  }
-}
-actions {
-  preamble {
     id: 16794308
     name: "set_egress_port"
     alias: "set_egress_port"
@@ -134,9 +141,9 @@
 }
 actions {
   preamble {
-    id: 16791212
-    name: "wcmp_group"
-    alias: "wcmp_group"
+    id: 16830055
+    name: "ecmp_group"
+    alias: "ecmp_group"
   }
   params {
     id: 1
@@ -153,16 +160,37 @@
 }
 actions {
   preamble {
-    id: 16793508
-    name: "drop"
-    alias: "drop"
+    id: 16784184
+    name: "_drop"
+    alias: "_drop"
   }
 }
 actions {
   preamble {
-    id: 16781545
-    name: "count_packet"
-    alias: "count_packet"
+    id: 16835928
+    name: "_packet_out"
+    alias: "_packet_out"
+  }
+}
+actions {
+  preamble {
+    id: 16822771
+    name: "count_egress"
+    alias: "count_egress"
+  }
+}
+actions {
+  preamble {
+    id: 16837943
+    name: "count_ingress"
+    alias: "count_ingress"
+  }
+}
+actions {
+  preamble {
+    id: 16835663
+    name: "add_packet_in_hdr"
+    alias: "add_packet_in_hdr"
   }
 }
 counters {
@@ -191,6 +219,17 @@
 }
 direct_counters {
   preamble {
+    id: 302009688
+    name: "ecmp_group_table_counter"
+    alias: "ecmp_group_table_counter"
+  }
+  spec {
+    unit: PACKETS
+  }
+  direct_table_id: 33612022
+}
+direct_counters {
+  preamble {
     id: 301990488
     name: "table0_counter"
     alias: "table0_counter"
@@ -200,14 +239,28 @@
   }
   direct_table_id: 33617813
 }
-direct_counters {
+# Manually adding controller_packet_metadata for packet I/O since P4_14 doesn't support annotations.
+controller_packet_metadata {
   preamble {
-    id: 302006421
-    name: "wcmp_group_table_counter"
-    alias: "wcmp_group_table_counter"
+    id: 2868941301
+    name: "packet_in"
+    annotations: "@controller_header(\"packet_in\")"
   }
-  spec {
-    unit: PACKETS
+  metadata {
+    id: 1
+    name: "ingress_port"
+    bitwidth: 9
   }
-  direct_table_id: 33596222
+}
+controller_packet_metadata {
+  preamble {
+    id: 2868916615
+    name: "packet_out"
+    annotations: "@controller_header(\"packet_out\")"
+  }
+  metadata {
+    id: 1
+    name: "egress_port"
+    bitwidth: 9
+  }
 }
diff --git a/tools/test/p4src/p4-14/p4c-out/wcmp.json b/tools/test/p4src/p4-14/p4c-out/wcmp.json
index 173dfe1..6313d0d 100644
--- a/tools/test/p4src/p4-14/p4c-out/wcmp.json
+++ b/tools/test/p4src/p4-14/p4c-out/wcmp.json
@@ -9,8 +9,10 @@
       "name" : "scalars_0",
       "id" : 0,
       "fields" : [
-        ["tmp", 32, false],
-        ["tmp_0", 32, false]
+        ["tmp_0", 104, false],
+        ["tmp", 8, false],
+        ["tmp_1", 32, false],
+        ["tmp_2", 32, false]
       ]
     },
     {
@@ -41,9 +43,25 @@
       ]
     },
     {
-      "name" : "tcp_t",
+      "name" : "packet_in_t",
       "id" : 3,
       "fields" : [
+        ["ingress_port", 9, false],
+        ["_padding", 7, false]
+      ]
+    },
+    {
+      "name" : "packet_out_t",
+      "id" : 4,
+      "fields" : [
+        ["egress_port", 9, false],
+        ["_padding_0", 7, false]
+      ]
+    },
+    {
+      "name" : "tcp_t",
+      "id" : 5,
+      "fields" : [
         ["srcPort", 16, false],
         ["dstPort", 16, false],
         ["seqNo", 32, false],
@@ -59,7 +77,7 @@
     },
     {
       "name" : "udp_t",
-      "id" : 4,
+      "id" : 6,
       "fields" : [
         ["srcPort", 16, false],
         ["dstPort", 16, false],
@@ -68,18 +86,8 @@
       ]
     },
     {
-      "name" : "intrinsic_metadata_t",
-      "id" : 5,
-      "fields" : [
-        ["ingress_global_timestamp", 32, false],
-        ["lf_field_list", 32, false],
-        ["mcast_grp", 16, false],
-        ["egress_rid", 16, false]
-      ]
-    },
-    {
       "name" : "wcmp_meta_t",
-      "id" : 6,
+      "id" : 7,
       "fields" : [
         ["groupId", 16, false],
         ["numBits", 8, false],
@@ -88,7 +96,7 @@
     },
     {
       "name" : "standard_metadata",
-      "id" : 7,
+      "id" : 8,
       "fields" : [
         ["ingress_port", 9, false],
         ["egress_spec", 9, false],
@@ -107,7 +115,7 @@
         ["mcast_grp", 16, false],
         ["resubmit_flag", 1, false],
         ["egress_rid", 16, false],
-        ["_padding", 5, false]
+        ["_padding_1", 5, false]
       ]
     }
   ],
@@ -141,29 +149,36 @@
       "pi_omit" : true
     },
     {
-      "name" : "tcp",
+      "name" : "packet_in_hdr",
       "id" : 4,
+      "header_type" : "packet_in_t",
+      "metadata" : false,
+      "pi_omit" : true
+    },
+    {
+      "name" : "packet_out_hdr",
+      "id" : 5,
+      "header_type" : "packet_out_t",
+      "metadata" : false,
+      "pi_omit" : true
+    },
+    {
+      "name" : "tcp",
+      "id" : 6,
       "header_type" : "tcp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "udp",
-      "id" : 5,
+      "id" : 7,
       "header_type" : "udp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
-      "name" : "intrinsic_metadata",
-      "id" : 6,
-      "header_type" : "intrinsic_metadata_t",
-      "metadata" : true,
-      "pi_omit" : true
-    },
-    {
       "name" : "wcmp_meta",
-      "id" : 7,
+      "id" : 8,
       "header_type" : "wcmp_meta_t",
       "metadata" : true,
       "pi_omit" : true
@@ -190,8 +205,31 @@
       "init_state" : "start",
       "parse_states" : [
         {
-          "name" : "parse_ethernet",
+          "name" : "default_parser",
           "id" : 0,
+          "parser_ops" : [],
+          "transitions" : [
+            {
+              "value" : "0x00ff",
+              "mask" : null,
+              "next_state" : "parse_pkt_out"
+            },
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "ingress_port"]
+            }
+          ]
+        },
+        {
+          "name" : "parse_ethernet",
+          "id" : 1,
           "parser_ops" : [
             {
               "parameters" : [
@@ -224,7 +262,7 @@
         },
         {
           "name" : "parse_ipv4",
-          "id" : 1,
+          "id" : 2,
           "parser_ops" : [
             {
               "parameters" : [
@@ -265,8 +303,54 @@
           ]
         },
         {
+          "name" : "parse_pkt_in",
+          "id" : 3,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "regular",
+                  "value" : "packet_in_hdr"
+                }
+              ],
+              "op" : "extract"
+            }
+          ],
+          "transitions" : [
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : []
+        },
+        {
+          "name" : "parse_pkt_out",
+          "id" : 4,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "regular",
+                  "value" : "packet_out_hdr"
+                }
+              ],
+              "op" : "extract"
+            }
+          ],
+          "transitions" : [
+            {
+              "value" : "default",
+              "mask" : null,
+              "next_state" : "parse_ethernet"
+            }
+          ],
+          "transition_key" : []
+        },
+        {
           "name" : "parse_tcp",
-          "id" : 2,
+          "id" : 5,
           "parser_ops" : [
             {
               "parameters" : [
@@ -289,7 +373,7 @@
         },
         {
           "name" : "parse_udp",
-          "id" : 3,
+          "id" : 6,
           "parser_ops" : [
             {
               "parameters" : [
@@ -312,16 +396,66 @@
         },
         {
           "name" : "start",
-          "id" : 4,
-          "parser_ops" : [],
+          "id" : 7,
+          "parser_ops" : [
+            {
+              "parameters" : [
+                {
+                  "type" : "field",
+                  "value" : ["scalars", "tmp_0"]
+                },
+                {
+                  "type" : "lookahead",
+                  "value" : [0, 104]
+                }
+              ],
+              "op" : "set"
+            },
+            {
+              "parameters" : [
+                {
+                  "type" : "field",
+                  "value" : ["scalars", "tmp"]
+                },
+                {
+                  "type" : "expression",
+                  "value" : {
+                    "type" : "expression",
+                    "value" : {
+                      "op" : "&",
+                      "left" : {
+                        "type" : "field",
+                        "value" : ["scalars", "tmp_0"]
+                      },
+                      "right" : {
+                        "type" : "hexstr",
+                        "value" : "0xff"
+                      }
+                    }
+                  }
+                }
+              ],
+              "op" : "set"
+            }
+          ],
           "transitions" : [
             {
+              "value" : "0x00",
+              "mask" : null,
+              "next_state" : "parse_pkt_in"
+            },
+            {
               "value" : "default",
               "mask" : null,
-              "next_state" : "parse_ethernet"
+              "next_state" : "default_parser"
             }
           ],
-          "transition_key" : []
+          "transition_key" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp"]
+            }
+          ]
         }
       ]
     }
@@ -330,7 +464,7 @@
     {
       "name" : "deparser",
       "id" : 0,
-      "order" : ["ethernet", "ipv4", "udp", "tcp"]
+      "order" : ["packet_out_hdr", "packet_in_hdr", "ethernet", "ipv4", "udp", "tcp"]
     }
   ],
   "meter_arrays" : [],
@@ -401,10 +535,45 @@
   "learn_lists" : [],
   "actions" : [
     {
-      "name" : "NoAction",
+      "name" : "add_packet_in_hdr",
       "id" : 0,
       "runtime_data" : [],
-      "primitives" : []
+      "primitives" : [
+        {
+          "op" : "add_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "packet_in_hdr"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 25,
+            "column" : 4,
+            "source_fragment" : "add_header(packet_in_hdr)"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["packet_in_hdr", "ingress_port"]
+            },
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "ingress_port"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 26,
+            "column" : 4,
+            "source_fragment" : "modify_field(packet_in_hdr.ingress_port, standard_metadata.ingress_port)"
+          }
+        }
+      ]
     },
     {
       "name" : "NoAction",
@@ -536,7 +705,7 @@
           ],
           "source_info" : {
             "filename" : "wcmp.p4",
-            "line" : 43,
+            "line" : 44,
             "column" : 4,
             "source_fragment" : "modify_field(wcmp_meta.selector, ..."
           }
@@ -567,7 +736,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 1,
+            "line" : 5,
             "column" : 23,
             "source_fragment" : "port) { ..."
           }
@@ -598,7 +767,7 @@
           ],
           "source_info" : {
             "filename" : "wcmp.p4",
-            "line" : 37,
+            "line" : 38,
             "column" : 18,
             "source_fragment" : "groupId) { ..."
           }
@@ -625,7 +794,7 @@
           ],
           "source_info" : {
             "filename" : "wcmp.p4",
-            "line" : 39,
+            "line" : 40,
             "column" : 4,
             "source_fragment" : "modify_field_with_hash_based_offset(wcmp_meta.numBits, 2, wcmp_hash, (32 - 2))"
           }
@@ -651,7 +820,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 10,
+            "line" : 21,
             "column" : 4,
             "source_fragment" : "modify_field(standard_metadata.egress_spec, 255)"
           }
@@ -659,7 +828,7 @@
       ]
     },
     {
-      "name" : "drop",
+      "name" : "_drop",
       "id" : 8,
       "runtime_data" : [],
       "primitives" : [
@@ -677,7 +846,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 6,
+            "line" : 13,
             "column" : 4,
             "source_fragment" : "modify_field(standard_metadata.egress_spec, 511)"
           }
@@ -708,7 +877,7 @@
           ],
           "source_info" : {
             "filename" : "include/actions.p4",
-            "line" : 1,
+            "line" : 5,
             "column" : 23,
             "source_fragment" : "port) { ..."
           }
@@ -716,7 +885,7 @@
       ]
     },
     {
-      "name" : "count_packet",
+      "name" : "_packet_out",
       "id" : 10,
       "runtime_data" : [],
       "primitives" : [
@@ -725,52 +894,48 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "field",
-                    "value" : ["standard_metadata", "ingress_port"]
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
-          "op" : "count",
-          "parameters" : [
-            {
-              "type" : "counter_array",
-              "value" : "ingress_port_counter"
+              "value" : ["standard_metadata", "egress_spec"]
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
+              "value" : ["packet_out_hdr", "egress_port"]
             }
           ],
           "source_info" : {
-            "filename" : "include/port_counters.p4",
-            "line" : 20,
+            "filename" : "include/packet_io.p4",
+            "line" : 7,
             "column" : 4,
-            "source_fragment" : "count(ingress_port_counter, standard_metadata.ingress_port)"
+            "source_fragment" : "modify_field(standard_metadata.egress_spec, packet_out_hdr.egress_port)"
           }
         },
         {
+          "op" : "remove_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "packet_out_hdr"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 8,
+            "column" : 4,
+            "source_fragment" : "remove_header(packet_out_hdr)"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "count_egress",
+      "id" : 11,
+      "runtime_data" : [],
+      "primitives" : [
+        {
           "op" : "assign",
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp_1"]
             },
             {
               "type" : "expression",
@@ -800,31 +965,112 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp_1"]
             }
           ],
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 21,
+            "line" : 22,
             "column" : 4,
             "source_fragment" : "count(egress_port_counter, standard_metadata.egress_spec)"
           }
         }
       ]
+    },
+    {
+      "name" : "count_ingress",
+      "id" : 12,
+      "runtime_data" : [],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_2"]
+            },
+            {
+              "type" : "expression",
+              "value" : {
+                "type" : "expression",
+                "value" : {
+                  "op" : "&",
+                  "left" : {
+                    "type" : "field",
+                    "value" : ["standard_metadata", "ingress_port"]
+                  },
+                  "right" : {
+                    "type" : "hexstr",
+                    "value" : "0xffffffff"
+                  }
+                }
+              }
+            }
+          ]
+        },
+        {
+          "op" : "count",
+          "parameters" : [
+            {
+              "type" : "counter_array",
+              "value" : "ingress_port_counter"
+            },
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_2"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 18,
+            "column" : 4,
+            "source_fragment" : "count(ingress_port_counter, standard_metadata.ingress_port)"
+          }
+        }
+      ]
     }
   ],
   "pipelines" : [
     {
       "name" : "ingress",
       "id" : 0,
-      "init_table" : "table0",
+      "init_table" : "node_2",
       "tables" : [
         {
-          "name" : "table0",
+          "name" : "ingress_pkt",
           "id" : 0,
           "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 11,
+            "column" : 0,
+            "source_fragment" : "table ingress_pkt { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [10],
+          "actions" : ["_packet_out"],
+          "base_default_next" : "node_4",
+          "next_tables" : {
+            "_packet_out" : "node_4"
+          },
+          "default_entry" : {
+            "action_id" : 10,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        },
+        {
+          "name" : "table0",
+          "id" : 1,
+          "source_info" : {
             "filename" : "wcmp.p4",
-            "line" : 47,
+            "line" : 48,
             "column" : 0,
             "source_fragment" : "table table0 { ..."
           },
@@ -856,18 +1102,18 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [5, 6, 7, 8, 0],
-          "actions" : ["set_egress_port", "wcmp_group", "send_to_cpu", "drop", "NoAction"],
-          "base_default_next" : "node_5",
+          "action_ids" : [5, 6, 7, 8, 1],
+          "actions" : ["set_egress_port", "wcmp_group", "send_to_cpu", "_drop", "NoAction"],
+          "base_default_next" : "node_8",
           "next_tables" : {
             "wcmp_group" : "wcmp_set_selector_table",
-            "set_egress_port" : "node_5",
-            "send_to_cpu" : "node_5",
-            "drop" : "node_5",
-            "NoAction" : "node_5"
+            "set_egress_port" : "node_8",
+            "send_to_cpu" : "node_8",
+            "_drop" : "node_8",
+            "NoAction" : "node_8"
           },
           "default_entry" : {
-            "action_id" : 0,
+            "action_id" : 1,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -875,10 +1121,10 @@
         },
         {
           "name" : "wcmp_set_selector_table",
-          "id" : 1,
+          "id" : 2,
           "source_info" : {
             "filename" : "wcmp.p4",
-            "line" : 63,
+            "line" : 64,
             "column" : 0,
             "source_fragment" : "table wcmp_set_selector_table { ..."
           },
@@ -889,15 +1135,15 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [4, 2],
+          "action_ids" : [4, 3],
           "actions" : ["wcmp_set_selector", "NoAction"],
-          "base_default_next" : "node_5",
+          "base_default_next" : "node_8",
           "next_tables" : {
             "wcmp_set_selector" : "wcmp_group_table",
-            "NoAction" : "node_5"
+            "NoAction" : "node_8"
           },
           "default_entry" : {
-            "action_id" : 2,
+            "action_id" : 3,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -905,10 +1151,10 @@
         },
         {
           "name" : "wcmp_group_table",
-          "id" : 2,
+          "id" : 3,
           "source_info" : {
             "filename" : "wcmp.p4",
-            "line" : 69,
+            "line" : 70,
             "column" : 0,
             "source_fragment" : "table wcmp_group_table { ..."
           },
@@ -930,28 +1176,28 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [9, 1],
+          "action_ids" : [9, 2],
           "actions" : ["set_egress_port", "NoAction"],
-          "base_default_next" : "node_5",
+          "base_default_next" : "node_8",
           "next_tables" : {
-            "set_egress_port" : "node_5",
-            "NoAction" : "node_5"
+            "set_egress_port" : "node_8",
+            "NoAction" : "node_8"
           },
           "default_entry" : {
-            "action_id" : 1,
+            "action_id" : 2,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
           }
         },
         {
-          "name" : "port_count_table",
-          "id" : 3,
+          "name" : "ingress_port_count_table",
+          "id" : 4,
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 13,
+            "line" : 25,
             "column" : 0,
-            "source_fragment" : "table port_count_table { ..."
+            "source_fragment" : "table ingress_port_count_table { ..."
           },
           "key" : [],
           "match_type" : "exact",
@@ -960,15 +1206,43 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [10, 3],
-          "actions" : ["count_packet", "NoAction"],
-          "base_default_next" : null,
+          "action_ids" : [12],
+          "actions" : ["count_ingress"],
+          "base_default_next" : "egress_port_count_table",
           "next_tables" : {
-            "count_packet" : null,
-            "NoAction" : null
+            "count_ingress" : "egress_port_count_table"
           },
           "default_entry" : {
-            "action_id" : 3,
+            "action_id" : 12,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        },
+        {
+          "name" : "egress_port_count_table",
+          "id" : 5,
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 30,
+            "column" : 0,
+            "source_fragment" : "table egress_port_count_table { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [11],
+          "actions" : ["count_egress"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "count_egress" : null
+          },
+          "default_entry" : {
+            "action_id" : 11,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -978,12 +1252,64 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_5",
+          "name" : "node_2",
           "id" : 0,
           "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 19,
+            "column" : 8,
+            "source_fragment" : "valid(packet_out_hdr)"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "==",
+              "left" : {
+                "type" : "field",
+                "value" : ["packet_out_hdr", "$valid$"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x01"
+              }
+            }
+          },
+          "true_next" : "ingress_pkt",
+          "false_next" : "node_4"
+        },
+        {
+          "name" : "node_4",
+          "id" : 1,
+          "source_info" : {
+            "filename" : "wcmp.p4",
+            "line" : 94,
+            "column" : 12,
+            "source_fragment" : "valid(packet_out_hdr)"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "!=",
+              "left" : {
+                "type" : "field",
+                "value" : ["packet_out_hdr", "$valid$"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x01"
+              }
+            }
+          },
+          "true_next" : "table0",
+          "false_next" : "node_8"
+        },
+        {
+          "name" : "node_8",
+          "id" : 2,
+          "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 26,
-            "column" : 35,
+            "line" : 36,
+            "column" : 38,
             "source_fragment" : "<"
           },
           "expression" : {
@@ -1001,17 +1327,74 @@
             }
           },
           "false_next" : null,
-          "true_next" : "port_count_table"
+          "true_next" : "ingress_port_count_table"
         }
       ]
     },
     {
       "name" : "egress",
       "id" : 1,
-      "init_table" : null,
-      "tables" : [],
+      "init_table" : "node_13",
+      "tables" : [
+        {
+          "name" : "egress_pkt",
+          "id" : 6,
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 29,
+            "column" : 0,
+            "source_fragment" : "table egress_pkt { ..."
+          },
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [0],
+          "actions" : ["add_packet_in_hdr"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "add_packet_in_hdr" : null
+          },
+          "default_entry" : {
+            "action_id" : 0,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
+          }
+        }
+      ],
       "action_profiles" : [],
-      "conditionals" : []
+      "conditionals" : [
+        {
+          "name" : "node_13",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/packet_io.p4",
+            "line" : 40,
+            "column" : 39,
+            "source_fragment" : "=="
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "==",
+              "left" : {
+                "type" : "field",
+                "value" : ["standard_metadata", "ingress_port"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x00ff"
+              }
+            }
+          },
+          "false_next" : null,
+          "true_next" : "egress_pkt"
+        }
+      ]
     }
   ],
   "checksums" : [],
diff --git a/tools/test/p4src/p4-14/p4c-out/wcmp.p4info b/tools/test/p4src/p4-14/p4c-out/wcmp.p4info
new file mode 100644
index 0000000..8024064
--- /dev/null
+++ b/tools/test/p4src/p4-14/p4c-out/wcmp.p4info
@@ -0,0 +1,288 @@
+tables {
+  preamble {
+    id: 33617813
+    name: "table0"
+    alias: "table0"
+  }
+  match_fields {
+    id: 1
+    name: "standard_metadata.ingress_port"
+    bitwidth: 9
+    match_type: TERNARY
+  }
+  match_fields {
+    id: 2
+    name: "ethernet.dstAddr"
+    bitwidth: 48
+    match_type: TERNARY
+  }
+  match_fields {
+    id: 3
+    name: "ethernet.srcAddr"
+    bitwidth: 48
+    match_type: TERNARY
+  }
+  match_fields {
+    id: 4
+    name: "ethernet.etherType"
+    bitwidth: 16
+    match_type: TERNARY
+  }
+  action_refs {
+    id: 16794308
+  }
+  action_refs {
+    id: 16791212
+  }
+  action_refs {
+    id: 16829080
+  }
+  action_refs {
+    id: 16784184
+  }
+  action_refs {
+    id: 16800567
+    annotations: "@defaultonly()"
+  }
+  direct_resource_ids: 301990488
+  size: 1024
+  with_entry_timeout: true
+}
+tables {
+  preamble {
+    id: 33596222
+    name: "wcmp_group_table"
+    alias: "wcmp_group_table"
+  }
+  match_fields {
+    id: 1
+    name: "wcmp_meta.groupId"
+    bitwidth: 16
+    match_type: EXACT
+  }
+  match_fields {
+    id: 2
+    name: "wcmp_meta.selector"
+    bitwidth: 32
+    match_type: LPM
+  }
+  action_refs {
+    id: 16794308
+  }
+  action_refs {
+    id: 16800567
+    annotations: "@defaultonly()"
+  }
+  direct_resource_ids: 302006421
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33613026
+    name: "wcmp_set_selector_table"
+    alias: "wcmp_set_selector_table"
+  }
+  action_refs {
+    id: 16819919
+  }
+  action_refs {
+    id: 16800567
+    annotations: "@defaultonly()"
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33560548
+    name: "ingress_pkt"
+    alias: "ingress_pkt"
+  }
+  action_refs {
+    id: 16835928
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33618793
+    name: "egress_port_count_table"
+    alias: "egress_port_count_table"
+  }
+  action_refs {
+    id: 16822771
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33579767
+    name: "ingress_port_count_table"
+    alias: "ingress_port_count_table"
+  }
+  action_refs {
+    id: 16837943
+  }
+  size: 1024
+}
+tables {
+  preamble {
+    id: 33608529
+    name: "egress_pkt"
+    alias: "egress_pkt"
+  }
+  action_refs {
+    id: 16835663
+  }
+  size: 1024
+}
+actions {
+  preamble {
+    id: 16800567
+    name: "NoAction"
+    alias: "NoAction"
+  }
+}
+actions {
+  preamble {
+    id: 16819919
+    name: "wcmp_set_selector"
+    alias: "wcmp_set_selector"
+  }
+}
+actions {
+  preamble {
+    id: 16794308
+    name: "set_egress_port"
+    alias: "set_egress_port"
+  }
+  params {
+    id: 1
+    name: "port"
+    bitwidth: 9
+  }
+}
+actions {
+  preamble {
+    id: 16791212
+    name: "wcmp_group"
+    alias: "wcmp_group"
+  }
+  params {
+    id: 1
+    name: "groupId"
+    bitwidth: 16
+  }
+}
+actions {
+  preamble {
+    id: 16829080
+    name: "send_to_cpu"
+    alias: "send_to_cpu"
+  }
+}
+actions {
+  preamble {
+    id: 16784184
+    name: "_drop"
+    alias: "_drop"
+  }
+}
+actions {
+  preamble {
+    id: 16835928
+    name: "_packet_out"
+    alias: "_packet_out"
+  }
+}
+actions {
+  preamble {
+    id: 16822771
+    name: "count_egress"
+    alias: "count_egress"
+  }
+}
+actions {
+  preamble {
+    id: 16837943
+    name: "count_ingress"
+    alias: "count_ingress"
+  }
+}
+actions {
+  preamble {
+    id: 16835663
+    name: "add_packet_in_hdr"
+    alias: "add_packet_in_hdr"
+  }
+}
+counters {
+  preamble {
+    id: 302008596
+    name: "egress_port_counter"
+    alias: "egress_port_counter"
+    annotations: "@min_width(32)"
+  }
+  spec {
+    unit: PACKETS
+  }
+  size: 254
+}
+counters {
+  preamble {
+    id: 301991238
+    name: "ingress_port_counter"
+    alias: "ingress_port_counter"
+    annotations: "@min_width(32)"
+  }
+  spec {
+    unit: PACKETS
+  }
+  size: 254
+}
+direct_counters {
+  preamble {
+    id: 301990488
+    name: "table0_counter"
+    alias: "table0_counter"
+  }
+  spec {
+    unit: PACKETS
+  }
+  direct_table_id: 33617813
+}
+direct_counters {
+  preamble {
+    id: 302006421
+    name: "wcmp_group_table_counter"
+    alias: "wcmp_group_table_counter"
+  }
+  spec {
+    unit: PACKETS
+  }
+  direct_table_id: 33596222
+}
+# Manually adding controller_packet_metadata for packet I/O since P4_14 doesn't support annotations.
+controller_packet_metadata {
+  preamble {
+    id: 2868941301
+    name: "packet_in"
+    annotations: "@controller_header(\"packet_in\")"
+  }
+  metadata {
+    id: 1
+    name: "ingress_port"
+    bitwidth: 9
+  }
+}
+controller_packet_metadata {
+  preamble {
+    id: 2868916615
+    name: "packet_out"
+    annotations: "@controller_header(\"packet_out\")"
+  }
+  metadata {
+    id: 1
+    name: "egress_port"
+    bitwidth: 9
+  }
+}
diff --git a/tools/test/p4src/p4-14/wcmp.p4 b/tools/test/p4src/p4-14/wcmp.p4
index d24183f..a388be7 100644
--- a/tools/test/p4src/p4-14/wcmp.p4
+++ b/tools/test/p4src/p4-14/wcmp.p4
@@ -3,6 +3,7 @@
 #include "include/parser.p4"
 #include "include/actions.p4"
 #include "include/port_counters.p4"
+#include "include/packet_io.p4"
 
 #define SELECTOR_WIDTH 32
 
@@ -46,16 +47,16 @@
 
 table table0 {
     reads {
-        standard_metadata.ingress_port : ternary;
-        ethernet.dstAddr : ternary;
-        ethernet.srcAddr : ternary;
+        IGR_PORT_FIELD     : ternary;
+        ethernet.dstAddr   : ternary;
+        ethernet.srcAddr   : ternary;
         ethernet.etherType : ternary;
     }
     actions {
         set_egress_port;
         wcmp_group;
         send_to_cpu;
-        drop;
+        _drop;
     }
     support_timeout: true;
 }
@@ -89,14 +90,21 @@
 }
 
 control ingress {
-    apply(table0) {
-        wcmp_group {
-            apply(wcmp_set_selector_table) {
-                wcmp_set_selector {
-                    apply(wcmp_group_table);
+    ingress_pkt_io();
+    if (not valid(packet_out_hdr)) {
+        apply(table0) {
+            wcmp_group {
+                apply(wcmp_set_selector_table) {
+                    wcmp_set_selector {
+                        apply(wcmp_group_table);
+                    }
                 }
             }
         }
     }
     process_port_counters();
-}
\ No newline at end of file
+}
+
+control egress {
+    egress_pkt_io();
+}