Fixed bug in P4_16 programs that was making bmv2 crash

Change-Id: Ia5057b3080e55610605908cd36b399db6c50c545
diff --git a/tools/test/p4src/p4-16/include/defines.p4 b/tools/test/p4src/p4-16/include/defines.p4
index ea6747a..c8640a8 100644
--- a/tools/test/p4src/p4-16/include/defines.p4
+++ b/tools/test/p4src/p4-16/include/defines.p4
@@ -17,7 +17,7 @@
 #ifndef DEFINES
 #define DEFINES
 
-#define MAX_PORTS 254
+#define MAX_PORTS 255
 
 #define ETH_TYPE_IPV4 16w0x800
 #define IP_TYPE_TCP 8w6
diff --git a/tools/test/p4src/p4-16/include/port_counters.p4 b/tools/test/p4src/p4-16/include/port_counters.p4
index 15ed02f..d8667a3 100644
--- a/tools/test/p4src/p4-16/include/port_counters.p4
+++ b/tools/test/p4src/p4-16/include/port_counters.p4
@@ -24,9 +24,11 @@
 
     apply {
         if (standard_metadata.egress_spec < MAX_PORTS) {
-            ingress_port_counter.count((bit<32>)standard_metadata.ingress_port);
             egress_port_counter.count((bit<32>)standard_metadata.egress_spec);
         }
+        if (standard_metadata.ingress_port < MAX_PORTS) {
+            ingress_port_counter.count((bit<32>)standard_metadata.ingress_port);
+        }
     }
 }
 #endif