Fixed packet I/O in p4-14 programs

Tested on BMv2 and working

Change-Id: I834d7b5a8627181c6888500545e1bdbfe9af8dc1
diff --git a/tools/test/p4src/p4-14/include/actions.p4 b/tools/test/p4src/p4-14/include/actions.p4
index 961890d..1e6d425 100644
--- a/tools/test/p4src/p4-14/include/actions.p4
+++ b/tools/test/p4src/p4-14/include/actions.p4
@@ -15,10 +15,8 @@
 }
 
 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);
-    #endif
+    modify_field(EGR_PORT_FIELD, CPU_PORT);
+    add_header(packet_in_hdr);
+    modify_field(packet_in_hdr.ingress_port, IGR_PORT_FIELD);
 }
 #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 35baa4f..e054493 100644
--- a/tools/test/p4src/p4-14/include/defines.p4
+++ b/tools/test/p4src/p4-14/include/defines.p4
@@ -1,8 +1,7 @@
 // Logic ports as defined in the simple_switch target
-#define MAX_PORTS 254
+#define MAX_PORTS 511
 #define DROP_PORT 511
 
-#define NULL_ETH_TYPE 0x00
 #define ETHERTYPE_IPV4 0x0800
 #define IP_PROTOCOLS_TCP  6
 #define IP_PROTOCOLS_UDP  17
diff --git a/tools/test/p4src/p4-14/include/packet_io.p4 b/tools/test/p4src/p4-14/include/packet_io.p4
index 5da7a65..5cd71a3 100644
--- a/tools/test/p4src/p4-14/include/packet_io.p4
+++ b/tools/test/p4src/p4-14/include/packet_io.p4
@@ -3,43 +3,21 @@
 #include "headers.p4"
 #include "parser.p4"
 
-action _packet_out() {
+action _process_packet_out() {
     modify_field(EGR_PORT_FIELD, packet_out_hdr.egress_port);
     remove_header(packet_out_hdr);
 }
 
-table ingress_pkt {
+table process_packet_out_table {
     actions {
-        _packet_out;
+        _process_packet_out;
     }
-    default_action: _packet_out();
+    default_action: _process_packet_out();
 }
 
-control ingress_pkt_io {
+control ingress_pkt_io_control {
     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);
+        apply(process_packet_out_table);
     }
 }
 
diff --git a/tools/test/p4src/p4-14/include/parser.p4 b/tools/test/p4src/p4-14/include/parser.p4
index 73dcdfd..0223297 100644
--- a/tools/test/p4src/p4-14/include/parser.p4
+++ b/tools/test/p4src/p4-14/include/parser.p4
@@ -11,11 +11,12 @@
 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;
+    // Hack to force deparsing of packet_in hdr.
+    // We assume it's impossible to receive a pkt with the first 8 bits of etherType 0.
+    // p4c-tofino complains when switching over 16 bits, i.e. the full etherType
+    return select(current(96, 8)) {
+        0 : parse_pkt_in;
+        default  : default_parser;
     }
 }