Fixed bug in P4_16 programs that was making bmv2 crash

Change-Id: Ia5057b3080e55610605908cd36b399db6c50c545
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java
index 50b808e..c2cc0b5 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java
@@ -76,8 +76,7 @@
     /*
     If true, we avoid querying the device and return the content of the ENTRY_STORE.
      */
-    // TODO: can remove this check as soon as the BMv2 bug when reading ECMP entries is fixed.
-    private boolean ignoreDeviceWhenGet = true;
+    private boolean ignoreDeviceWhenGet = false;
 
     /*
     If true, we read all direct counters of a table with one request. Otherwise, send as many request as the number of
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
diff --git a/tools/test/p4src/p4-16/p4c-out/default.json b/tools/test/p4src/p4-16/p4c-out/default.json
index 2dd5c49..241cbe1 100644
--- a/tools/test/p4src/p4-16/p4c-out/default.json
+++ b/tools/test/p4src/p4-16/p4c-out/default.json
@@ -447,7 +447,7 @@
         "column" : 38,
         "source_fragment" : "egress_port_counter"
       },
-      "size" : 254,
+      "size" : 255,
       "is_direct" : false
     },
     {
@@ -459,7 +459,7 @@
         "column" : 38,
         "source_fragment" : "ingress_port_counter"
       },
-      "size" : 254,
+      "size" : 255,
       "is_direct" : false
     }
   ],
@@ -3248,51 +3248,6 @@
                   "op" : "&",
                   "left" : {
                     "type" : "field",
-                    "value" : ["standard_metadata", "ingress_port"]
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
-          "op" : "count",
-          "parameters" : [
-            {
-              "type" : "counter_array",
-              "value" : "port_counters_control.ingress_port_counter"
-            },
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp"]
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/port_counters.p4",
-            "line" : 27,
-            "column" : 12,
-            "source_fragment" : "ingress_port_counter.count((bit<32>)standard_metadata.ingress_port)"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp_0"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "field",
                     "value" : ["standard_metadata", "egress_spec"]
                   },
                   "right" : {
@@ -3313,12 +3268,12 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp"]
             }
           ],
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 28,
+            "line" : 27,
             "column" : 12,
             "source_fragment" : "egress_port_counter.count((bit<32>)standard_metadata.egress_spec)"
           }
@@ -3331,6 +3286,58 @@
       "runtime_data" : [],
       "primitives" : [
         {
+          "op" : "assign",
+          "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" : "port_counters_control.ingress_port_counter"
+            },
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_0"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 30,
+            "column" : 12,
+            "source_fragment" : "ingress_port_counter.count((bit<32>)standard_metadata.ingress_port)"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "act_2",
+      "id" : 9,
+      "runtime_data" : [],
+      "primitives" : [
+        {
           "op" : "add_header",
           "parameters" : [
             {
@@ -3367,8 +3374,8 @@
       ]
     },
     {
-      "name" : "act_2",
-      "id" : 9,
+      "name" : "act_3",
+      "id" : 10,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3518,9 +3525,9 @@
           "direct_meters" : null,
           "action_ids" : [7],
           "actions" : ["act_0"],
-          "base_default_next" : null,
+          "base_default_next" : "node_9",
           "next_tables" : {
-            "act_0" : null
+            "act_0" : "node_9"
           },
           "default_entry" : {
             "action_id" : 7,
@@ -3528,6 +3535,29 @@
             "action_data" : [],
             "action_entry_const" : true
           }
+        },
+        {
+          "name" : "tbl_act_1",
+          "id" : 4,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [8],
+          "actions" : ["act_1"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "act_1" : null
+          },
+          "default_entry" : {
+            "action_id" : 8,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
         }
       ],
       "action_profiles" : [
@@ -3630,7 +3660,7 @@
             "filename" : "include/port_counters.p4",
             "line" : 26,
             "column" : 12,
-            "source_fragment" : "standard_metadata.egress_spec < 254"
+            "source_fragment" : "standard_metadata.egress_spec < 255"
           },
           "expression" : {
             "type" : "expression",
@@ -3642,12 +3672,38 @@
               },
               "right" : {
                 "type" : "hexstr",
-                "value" : "0x00fe"
+                "value" : "0x00ff"
+              }
+            }
+          },
+          "true_next" : "tbl_act_0",
+          "false_next" : "node_9"
+        },
+        {
+          "name" : "node_9",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 29,
+            "column" : 12,
+            "source_fragment" : "standard_metadata.ingress_port < 255"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "<",
+              "left" : {
+                "type" : "field",
+                "value" : ["standard_metadata", "ingress_port"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x00ff"
               }
             }
           },
           "false_next" : null,
-          "true_next" : "tbl_act_0"
+          "true_next" : "tbl_act_1"
         }
       ]
     },
@@ -3660,32 +3716,9 @@
         "column" : 8,
         "source_fragment" : "egress"
       },
-      "init_table" : "tbl_act_1",
+      "init_table" : "tbl_act_2",
       "tables" : [
         {
-          "name" : "tbl_act_1",
-          "id" : 4,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [9],
-          "actions" : ["act_2"],
-          "base_default_next" : "node_12",
-          "next_tables" : {
-            "act_2" : "node_12"
-          },
-          "default_entry" : {
-            "action_id" : 9,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
           "name" : "tbl_act_2",
           "id" : 5,
           "key" : [],
@@ -3695,14 +3728,37 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [8],
-          "actions" : ["act_1"],
-          "base_default_next" : null,
+          "action_ids" : [10],
+          "actions" : ["act_3"],
+          "base_default_next" : "node_14",
           "next_tables" : {
-            "act_1" : null
+            "act_3" : "node_14"
           },
           "default_entry" : {
-            "action_id" : 8,
+            "action_id" : 10,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_act_3",
+          "id" : 6,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [9],
+          "actions" : ["act_2"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "act_2" : null
+          },
+          "default_entry" : {
+            "action_id" : 9,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3712,8 +3768,8 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_12",
-          "id" : 3,
+          "name" : "node_14",
+          "id" : 4,
           "source_info" : {
             "filename" : "include/packet_io.p4",
             "line" : 31,
@@ -3735,7 +3791,7 @@
             }
           },
           "false_next" : null,
-          "true_next" : "tbl_act_2"
+          "true_next" : "tbl_act_3"
         }
       ]
     }
diff --git a/tools/test/p4src/p4-16/p4c-out/default.p4info b/tools/test/p4src/p4-16/p4c-out/default.p4info
index 6bf4a27..d08d40a 100644
--- a/tools/test/p4src/p4-16/p4c-out/default.p4info
+++ b/tools/test/p4src/p4-16/p4c-out/default.p4info
@@ -130,7 +130,7 @@
   spec {
     unit: PACKETS
   }
-  size: 254
+  size: 255
 }
 counters {
   preamble {
@@ -141,7 +141,7 @@
   spec {
     unit: PACKETS
   }
-  size: 254
+  size: 255
 }
 direct_counters {
   preamble {
diff --git a/tools/test/p4src/p4-16/p4c-out/ecmp.json b/tools/test/p4src/p4-16/p4c-out/ecmp.json
index 506db53..2a23882 100644
--- a/tools/test/p4src/p4-16/p4c-out/ecmp.json
+++ b/tools/test/p4src/p4-16/p4c-out/ecmp.json
@@ -448,7 +448,7 @@
         "column" : 38,
         "source_fragment" : "egress_port_counter"
       },
-      "size" : 254,
+      "size" : 255,
       "is_direct" : false
     },
     {
@@ -460,7 +460,7 @@
         "column" : 38,
         "source_fragment" : "ingress_port_counter"
       },
-      "size" : 254,
+      "size" : 255,
       "is_direct" : false
     }
   ],
@@ -3312,51 +3312,6 @@
                   "op" : "&",
                   "left" : {
                     "type" : "field",
-                    "value" : ["standard_metadata", "ingress_port"]
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
-          "op" : "count",
-          "parameters" : [
-            {
-              "type" : "counter_array",
-              "value" : "port_counters_control.ingress_port_counter"
-            },
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp"]
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/port_counters.p4",
-            "line" : 27,
-            "column" : 12,
-            "source_fragment" : "ingress_port_counter.count((bit<32>)standard_metadata.ingress_port)"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp_0"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "field",
                     "value" : ["standard_metadata", "egress_spec"]
                   },
                   "right" : {
@@ -3377,12 +3332,12 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp"]
             }
           ],
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 28,
+            "line" : 27,
             "column" : 12,
             "source_fragment" : "egress_port_counter.count((bit<32>)standard_metadata.egress_spec)"
           }
@@ -3395,6 +3350,58 @@
       "runtime_data" : [],
       "primitives" : [
         {
+          "op" : "assign",
+          "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" : "port_counters_control.ingress_port_counter"
+            },
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_0"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 30,
+            "column" : 12,
+            "source_fragment" : "ingress_port_counter.count((bit<32>)standard_metadata.ingress_port)"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "act_2",
+      "id" : 9,
+      "runtime_data" : [],
+      "primitives" : [
+        {
           "op" : "add_header",
           "parameters" : [
             {
@@ -3431,8 +3438,8 @@
       ]
     },
     {
-      "name" : "act_2",
-      "id" : 9,
+      "name" : "act_3",
+      "id" : 10,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3592,9 +3599,9 @@
           "direct_meters" : null,
           "action_ids" : [7],
           "actions" : ["act_0"],
-          "base_default_next" : null,
+          "base_default_next" : "node_9",
           "next_tables" : {
-            "act_0" : null
+            "act_0" : "node_9"
           },
           "default_entry" : {
             "action_id" : 7,
@@ -3602,6 +3609,29 @@
             "action_data" : [],
             "action_entry_const" : true
           }
+        },
+        {
+          "name" : "tbl_act_1",
+          "id" : 4,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [8],
+          "actions" : ["act_1"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "act_1" : null
+          },
+          "default_entry" : {
+            "action_id" : 8,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
         }
       ],
       "action_profiles" : [],
@@ -3665,7 +3695,7 @@
             "filename" : "include/port_counters.p4",
             "line" : 26,
             "column" : 12,
-            "source_fragment" : "standard_metadata.egress_spec < 254"
+            "source_fragment" : "standard_metadata.egress_spec < 255"
           },
           "expression" : {
             "type" : "expression",
@@ -3677,12 +3707,38 @@
               },
               "right" : {
                 "type" : "hexstr",
-                "value" : "0x00fe"
+                "value" : "0x00ff"
+              }
+            }
+          },
+          "true_next" : "tbl_act_0",
+          "false_next" : "node_9"
+        },
+        {
+          "name" : "node_9",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 29,
+            "column" : 12,
+            "source_fragment" : "standard_metadata.ingress_port < 255"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "<",
+              "left" : {
+                "type" : "field",
+                "value" : ["standard_metadata", "ingress_port"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x00ff"
               }
             }
           },
           "false_next" : null,
-          "true_next" : "tbl_act_0"
+          "true_next" : "tbl_act_1"
         }
       ]
     },
@@ -3695,32 +3751,9 @@
         "column" : 8,
         "source_fragment" : "egress"
       },
-      "init_table" : "tbl_act_1",
+      "init_table" : "tbl_act_2",
       "tables" : [
         {
-          "name" : "tbl_act_1",
-          "id" : 4,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [9],
-          "actions" : ["act_2"],
-          "base_default_next" : "node_12",
-          "next_tables" : {
-            "act_2" : "node_12"
-          },
-          "default_entry" : {
-            "action_id" : 9,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
           "name" : "tbl_act_2",
           "id" : 5,
           "key" : [],
@@ -3730,14 +3763,37 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [8],
-          "actions" : ["act_1"],
-          "base_default_next" : null,
+          "action_ids" : [10],
+          "actions" : ["act_3"],
+          "base_default_next" : "node_14",
           "next_tables" : {
-            "act_1" : null
+            "act_3" : "node_14"
           },
           "default_entry" : {
-            "action_id" : 8,
+            "action_id" : 10,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_act_3",
+          "id" : 6,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [9],
+          "actions" : ["act_2"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "act_2" : null
+          },
+          "default_entry" : {
+            "action_id" : 9,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3747,8 +3803,8 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_12",
-          "id" : 3,
+          "name" : "node_14",
+          "id" : 4,
           "source_info" : {
             "filename" : "include/packet_io.p4",
             "line" : 31,
@@ -3770,7 +3826,7 @@
             }
           },
           "false_next" : null,
-          "true_next" : "tbl_act_2"
+          "true_next" : "tbl_act_3"
         }
       ]
     }
diff --git a/tools/test/p4src/p4-16/p4c-out/ecmp.p4info b/tools/test/p4src/p4-16/p4c-out/ecmp.p4info
index 29fd5c0..2355b90 100644
--- a/tools/test/p4src/p4-16/p4c-out/ecmp.p4info
+++ b/tools/test/p4src/p4-16/p4c-out/ecmp.p4info
@@ -126,7 +126,7 @@
   spec {
     unit: PACKETS
   }
-  size: 254
+  size: 255
 }
 counters {
   preamble {
@@ -137,7 +137,7 @@
   spec {
     unit: PACKETS
   }
-  size: 254
+  size: 255
 }
 direct_counters {
   preamble {
diff --git a/tools/test/p4src/p4-16/p4c-out/wcmp.json b/tools/test/p4src/p4-16/p4c-out/wcmp.json
index dc50c96..3367017 100644
--- a/tools/test/p4src/p4-16/p4c-out/wcmp.json
+++ b/tools/test/p4src/p4-16/p4c-out/wcmp.json
@@ -393,7 +393,7 @@
           "parser_ops" : [],
           "transitions" : [
             {
-              "value" : "0xff",
+              "value" : "0x00ff",
               "mask" : null,
               "next_state" : "parse_packet_out"
             },
@@ -449,7 +449,7 @@
         "column" : 38,
         "source_fragment" : "egress_port_counter"
       },
-      "size" : 254,
+      "size" : 255,
       "is_direct" : false
     },
     {
@@ -461,7 +461,7 @@
         "column" : 38,
         "source_fragment" : "ingress_port_counter"
       },
-      "size" : 254,
+      "size" : 255,
       "is_direct" : false
     }
   ],
@@ -3422,51 +3422,6 @@
                   "op" : "&",
                   "left" : {
                     "type" : "field",
-                    "value" : ["standard_metadata", "ingress_port"]
-                  },
-                  "right" : {
-                    "type" : "hexstr",
-                    "value" : "0xffffffff"
-                  }
-                }
-              }
-            }
-          ]
-        },
-        {
-          "op" : "count",
-          "parameters" : [
-            {
-              "type" : "counter_array",
-              "value" : "port_counters_control.ingress_port_counter"
-            },
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp"]
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/port_counters.p4",
-            "line" : 27,
-            "column" : 12,
-            "source_fragment" : "ingress_port_counter.count((bit<32>)standard_metadata.ingress_port)"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["scalars", "tmp_0"]
-            },
-            {
-              "type" : "expression",
-              "value" : {
-                "type" : "expression",
-                "value" : {
-                  "op" : "&",
-                  "left" : {
-                    "type" : "field",
                     "value" : ["standard_metadata", "egress_spec"]
                   },
                   "right" : {
@@ -3487,12 +3442,12 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_0"]
+              "value" : ["scalars", "tmp"]
             }
           ],
           "source_info" : {
             "filename" : "include/port_counters.p4",
-            "line" : 28,
+            "line" : 27,
             "column" : 12,
             "source_fragment" : "egress_port_counter.count((bit<32>)standard_metadata.egress_spec)"
           }
@@ -3505,6 +3460,58 @@
       "runtime_data" : [],
       "primitives" : [
         {
+          "op" : "assign",
+          "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" : "port_counters_control.ingress_port_counter"
+            },
+            {
+              "type" : "field",
+              "value" : ["scalars", "tmp_0"]
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 30,
+            "column" : 12,
+            "source_fragment" : "ingress_port_counter.count((bit<32>)standard_metadata.ingress_port)"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "act_2",
+      "id" : 10,
+      "runtime_data" : [],
+      "primitives" : [
+        {
           "op" : "add_header",
           "parameters" : [
             {
@@ -3541,8 +3548,8 @@
       ]
     },
     {
-      "name" : "act_2",
-      "id" : 10,
+      "name" : "act_3",
+      "id" : 11,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3725,9 +3732,9 @@
           "direct_meters" : null,
           "action_ids" : [8],
           "actions" : ["act_0"],
-          "base_default_next" : null,
+          "base_default_next" : "node_10",
           "next_tables" : {
-            "act_0" : null
+            "act_0" : "node_10"
           },
           "default_entry" : {
             "action_id" : 8,
@@ -3735,6 +3742,29 @@
             "action_data" : [],
             "action_entry_const" : true
           }
+        },
+        {
+          "name" : "tbl_act_1",
+          "id" : 5,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [9],
+          "actions" : ["act_1"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "act_1" : null
+          },
+          "default_entry" : {
+            "action_id" : 9,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
         }
       ],
       "action_profiles" : [],
@@ -3798,7 +3828,7 @@
             "filename" : "include/port_counters.p4",
             "line" : 26,
             "column" : 12,
-            "source_fragment" : "standard_metadata.egress_spec < 254"
+            "source_fragment" : "standard_metadata.egress_spec < 255"
           },
           "expression" : {
             "type" : "expression",
@@ -3810,12 +3840,38 @@
               },
               "right" : {
                 "type" : "hexstr",
-                "value" : "0x00fe"
+                "value" : "0x00ff"
+              }
+            }
+          },
+          "true_next" : "tbl_act_0",
+          "false_next" : "node_10"
+        },
+        {
+          "name" : "node_10",
+          "id" : 3,
+          "source_info" : {
+            "filename" : "include/port_counters.p4",
+            "line" : 29,
+            "column" : 12,
+            "source_fragment" : "standard_metadata.ingress_port < 255"
+          },
+          "expression" : {
+            "type" : "expression",
+            "value" : {
+              "op" : "<",
+              "left" : {
+                "type" : "field",
+                "value" : ["standard_metadata", "ingress_port"]
+              },
+              "right" : {
+                "type" : "hexstr",
+                "value" : "0x00ff"
               }
             }
           },
           "false_next" : null,
-          "true_next" : "tbl_act_0"
+          "true_next" : "tbl_act_1"
         }
       ]
     },
@@ -3828,32 +3884,9 @@
         "column" : 8,
         "source_fragment" : "egress"
       },
-      "init_table" : "tbl_act_1",
+      "init_table" : "tbl_act_2",
       "tables" : [
         {
-          "name" : "tbl_act_1",
-          "id" : 5,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [10],
-          "actions" : ["act_2"],
-          "base_default_next" : "node_13",
-          "next_tables" : {
-            "act_2" : "node_13"
-          },
-          "default_entry" : {
-            "action_id" : 10,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
           "name" : "tbl_act_2",
           "id" : 6,
           "key" : [],
@@ -3863,14 +3896,37 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [9],
-          "actions" : ["act_1"],
-          "base_default_next" : null,
+          "action_ids" : [11],
+          "actions" : ["act_3"],
+          "base_default_next" : "node_15",
           "next_tables" : {
-            "act_1" : null
+            "act_3" : "node_15"
           },
           "default_entry" : {
-            "action_id" : 9,
+            "action_id" : 11,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_act_3",
+          "id" : 7,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [10],
+          "actions" : ["act_2"],
+          "base_default_next" : null,
+          "next_tables" : {
+            "act_2" : null
+          },
+          "default_entry" : {
+            "action_id" : 10,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3880,8 +3936,8 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_13",
-          "id" : 3,
+          "name" : "node_15",
+          "id" : 4,
           "source_info" : {
             "filename" : "include/packet_io.p4",
             "line" : 31,
@@ -3903,7 +3959,7 @@
             }
           },
           "false_next" : null,
-          "true_next" : "tbl_act_2"
+          "true_next" : "tbl_act_3"
         }
       ]
     }
diff --git a/tools/test/p4src/p4-16/p4c-out/wcmp.p4info b/tools/test/p4src/p4-16/p4c-out/wcmp.p4info
index 41aabf4..b6c3b50 100644
--- a/tools/test/p4src/p4-16/p4c-out/wcmp.p4info
+++ b/tools/test/p4src/p4-16/p4c-out/wcmp.p4info
@@ -133,7 +133,7 @@
   spec {
     unit: PACKETS
   }
-  size: 254
+  size: 255
 }
 counters {
   preamble {
@@ -144,7 +144,7 @@
   spec {
     unit: PACKETS
   }
-  size: 254
+  size: 255
 }
 direct_counters {
   preamble {