Fixed egress port counter in tor.p4

Also, count both packets and bytes

Change-Id: I6c25a83738f295d1018c5075f9e3f2c9e4e90ce6
diff --git a/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/context.json b/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/context.json
index 936b3c1..865f226 100644
--- a/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/context.json
+++ b/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/context.json
@@ -1,5 +1,5 @@
 {
-  "build_date": "09/27/17 09:33:37",
+  "build_date": "10/03/17 07:16:52",
   "compiler_version": "6.0.0-pre-alpha.2",
   "program_name": "tor",
   "learn_quanta": [],
@@ -279,18 +279,18 @@
       "handle": 67108865,
       "name": "packetio_egress.ingress_port_counter",
       "table_type": "statistics",
-      "size": 4096,
+      "size": 2048,
       "stage_tables": [
         {
           "stage_number": 0,
-          "size": 4096,
+          "size": 2048,
           "stage_table_type": "statistics",
           "logical_table_id": 4,
           "pack_format": [
             {
               "table_word_width": 128,
               "memory_word_width": 128,
-              "entries_per_table_word": 4,
+              "entries_per_table_word": 2,
               "number_memory_units_per_table_word": 1 } ],
           "memory_resource_allocation": {
             "memory_type": "sram",
@@ -303,9 +303,9 @@
       "how_referenced": "indirect",
       "enable_pfe": false,
       "pfe_bit_position": 0,
-      "byte_counter_resolution": 32,
-      "packet_counter_resolution": 0,
-      "statistics_type": "bytes" },
+      "byte_counter_resolution": 36,
+      "packet_counter_resolution": 28,
+      "statistics_type": "packets_and_bytes" },
     {
       "direction": "egress",
       "handle": 16777221,
@@ -381,18 +381,18 @@
       "handle": 67108866,
       "name": "packetio_egress.egress_port_counter",
       "table_type": "statistics",
-      "size": 4096,
+      "size": 2048,
       "stage_tables": [
         {
           "stage_number": 0,
-          "size": 4096,
+          "size": 2048,
           "stage_table_type": "statistics",
           "logical_table_id": 5,
           "pack_format": [
             {
               "table_word_width": 128,
               "memory_word_width": 128,
-              "entries_per_table_word": 4,
+              "entries_per_table_word": 2,
               "number_memory_units_per_table_word": 1 } ],
           "memory_resource_allocation": {
             "memory_type": "sram",
@@ -405,9 +405,9 @@
       "how_referenced": "indirect",
       "enable_pfe": false,
       "pfe_bit_position": 0,
-      "byte_counter_resolution": 32,
-      "packet_counter_resolution": 0,
-      "statistics_type": "bytes" },
+      "byte_counter_resolution": 36,
+      "packet_counter_resolution": 28,
+      "statistics_type": "packets_and_bytes" },
     {
       "direction": "ingress",
       "handle": 16777222,
@@ -6963,7 +6963,7 @@
     {
       "fully_qualified_name": "mau[0].dp.match_input_xbar_din_power_ctl",
       "name": "stage_0_match_input_xbar_din_power_ctl",
-      "value": "0000000000000000000000000000000000000000000000080000000000000000000000000000000000000031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
+      "value": "0000000000000000000000000000000000000000000000080000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
     {
       "fully_qualified_name": "mau[0].dp.xbar_hash.hash.parity_group_mask",
       "name": "stage_0_parity_group_mask",
diff --git a/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tofino.bin b/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tofino.bin
index 91df4f7..8f7a9c5 100644
--- a/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tofino.bin
+++ b/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tofino.bin
Binary files differ
diff --git a/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tor.p4info b/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tor.p4info
index 44c994b..ebf32d0 100644
--- a/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tor.p4info
+++ b/tools/test/p4src/tor/p4c-out/tofino/tor/mavericks/tor.p4info
@@ -568,7 +568,7 @@
     alias: "egress_port_counter"
   }
   spec {
-    unit: BYTES
+    unit: BOTH
   }
   size: 510
 }
@@ -579,7 +579,7 @@
     alias: "ingress_port_counter"
   }
   spec {
-    unit: BYTES
+    unit: BOTH
   }
   size: 510
 }
diff --git a/tools/test/p4src/tor/p4c-out/tofino/tor/montara/context.json b/tools/test/p4src/tor/p4c-out/tofino/tor/montara/context.json
index 0cb93dc..684791d 100644
--- a/tools/test/p4src/tor/p4c-out/tofino/tor/montara/context.json
+++ b/tools/test/p4src/tor/p4c-out/tofino/tor/montara/context.json
@@ -1,5 +1,5 @@
 {
-  "build_date": "09/27/17 09:33:49",
+  "build_date": "10/03/17 07:17:04",
   "compiler_version": "6.0.0-pre-alpha.2",
   "program_name": "tor",
   "learn_quanta": [],
@@ -279,18 +279,18 @@
       "handle": 67108865,
       "name": "packetio_egress.ingress_port_counter",
       "table_type": "statistics",
-      "size": 4096,
+      "size": 2048,
       "stage_tables": [
         {
           "stage_number": 0,
-          "size": 4096,
+          "size": 2048,
           "stage_table_type": "statistics",
           "logical_table_id": 4,
           "pack_format": [
             {
               "table_word_width": 128,
               "memory_word_width": 128,
-              "entries_per_table_word": 4,
+              "entries_per_table_word": 2,
               "number_memory_units_per_table_word": 1 } ],
           "memory_resource_allocation": {
             "memory_type": "sram",
@@ -303,9 +303,9 @@
       "how_referenced": "indirect",
       "enable_pfe": false,
       "pfe_bit_position": 0,
-      "byte_counter_resolution": 32,
-      "packet_counter_resolution": 0,
-      "statistics_type": "bytes" },
+      "byte_counter_resolution": 36,
+      "packet_counter_resolution": 28,
+      "statistics_type": "packets_and_bytes" },
     {
       "direction": "egress",
       "handle": 16777221,
@@ -381,18 +381,18 @@
       "handle": 67108866,
       "name": "packetio_egress.egress_port_counter",
       "table_type": "statistics",
-      "size": 4096,
+      "size": 2048,
       "stage_tables": [
         {
           "stage_number": 0,
-          "size": 4096,
+          "size": 2048,
           "stage_table_type": "statistics",
           "logical_table_id": 5,
           "pack_format": [
             {
               "table_word_width": 128,
               "memory_word_width": 128,
-              "entries_per_table_word": 4,
+              "entries_per_table_word": 2,
               "number_memory_units_per_table_word": 1 } ],
           "memory_resource_allocation": {
             "memory_type": "sram",
@@ -405,9 +405,9 @@
       "how_referenced": "indirect",
       "enable_pfe": false,
       "pfe_bit_position": 0,
-      "byte_counter_resolution": 32,
-      "packet_counter_resolution": 0,
-      "statistics_type": "bytes" },
+      "byte_counter_resolution": 36,
+      "packet_counter_resolution": 28,
+      "statistics_type": "packets_and_bytes" },
     {
       "direction": "ingress",
       "handle": 16777222,
@@ -6963,7 +6963,7 @@
     {
       "fully_qualified_name": "mau[0].dp.match_input_xbar_din_power_ctl",
       "name": "stage_0_match_input_xbar_din_power_ctl",
-      "value": "0000000000000000000000000000000000000000000000080000000000000000000000000000000000000031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
+      "value": "0000000000000000000000000000000000000000000000080000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
     {
       "fully_qualified_name": "mau[0].dp.xbar_hash.hash.parity_group_mask",
       "name": "stage_0_parity_group_mask",
diff --git a/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tofino.bin b/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tofino.bin
index f8ad94b..82baaec 100644
--- a/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tofino.bin
+++ b/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tofino.bin
Binary files differ
diff --git a/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tor.p4info b/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tor.p4info
index 44c994b..ebf32d0 100644
--- a/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tor.p4info
+++ b/tools/test/p4src/tor/p4c-out/tofino/tor/montara/tor.p4info
@@ -568,7 +568,7 @@
     alias: "egress_port_counter"
   }
   spec {
-    unit: BYTES
+    unit: BOTH
   }
   size: 510
 }
@@ -579,7 +579,7 @@
     alias: "ingress_port_counter"
   }
   spec {
-    unit: BYTES
+    unit: BOTH
   }
   size: 510
 }
diff --git a/tools/test/p4src/tor/p4c-out/tor.json b/tools/test/p4src/tor/p4c-out/tor.json
index e48c28b..8a1ebcf 100644
--- a/tools/test/p4src/tor/p4c-out/tor.json
+++ b/tools/test/p4src/tor/p4c-out/tor.json
@@ -826,7 +826,7 @@
       "source_info" : {
         "filename" : "packetio.p4",
         "line" : 49,
-        "column" : 34,
+        "column" : 46,
         "source_fragment" : "egress_port_counter"
       },
       "size" : 510,
@@ -838,7 +838,7 @@
       "source_info" : {
         "filename" : "packetio.p4",
         "line" : 50,
-        "column" : 34,
+        "column" : 46,
         "source_fragment" : "ingress_port_counter"
       },
       "size" : 510,
@@ -1887,7 +1887,7 @@
                   "op" : "&",
                   "left" : {
                     "type" : "field",
-                    "value" : ["standard_metadata", "egress_spec"]
+                    "value" : ["standard_metadata", "egress_port"]
                   },
                   "right" : {
                     "type" : "hexstr",
@@ -1914,7 +1914,7 @@
             "filename" : "packetio.p4",
             "line" : 56,
             "column" : 6,
-            "source_fragment" : "egress_port_counter.count((bit<32>) standard_metadata.egress_spec)"
+            "source_fragment" : "egress_port_counter.count((bit<32>) standard_metadata.egress_port)"
           }
         }
       ]
diff --git a/tools/test/p4src/tor/p4c-out/tor.p4info b/tools/test/p4src/tor/p4c-out/tor.p4info
index 44c994b..ebf32d0 100644
--- a/tools/test/p4src/tor/p4c-out/tor.p4info
+++ b/tools/test/p4src/tor/p4c-out/tor.p4info
@@ -568,7 +568,7 @@
     alias: "egress_port_counter"
   }
   spec {
-    unit: BYTES
+    unit: BOTH
   }
   size: 510
 }
@@ -579,7 +579,7 @@
     alias: "ingress_port_counter"
   }
   spec {
-    unit: BYTES
+    unit: BOTH
   }
   size: 510
 }
diff --git a/tools/test/p4src/tor/packetio.p4 b/tools/test/p4src/tor/packetio.p4
index 65f073a..0c02dd2 100644
--- a/tools/test/p4src/tor/packetio.p4
+++ b/tools/test/p4src/tor/packetio.p4
@@ -46,14 +46,14 @@
 
   // L123-DEMO-HACK: BEGIN
   #define MAX_PORTS 510
-  counter(MAX_PORTS, CounterType.bytes) egress_port_counter;
-  counter(MAX_PORTS, CounterType.bytes) ingress_port_counter;
+  counter(MAX_PORTS, CounterType.packets_and_bytes) egress_port_counter;
+  counter(MAX_PORTS, CounterType.packets_and_bytes) ingress_port_counter;
   // L123-DEMO-HACK: END
 
   apply {
     // L123-DEMO-HACK: BEGIN
     if (standard_metadata.egress_port < MAX_PORTS) {
-      egress_port_counter.count((bit<32>) standard_metadata.egress_spec);
+      egress_port_counter.count((bit<32>) standard_metadata.egress_port);
     }
     if (standard_metadata.ingress_port < MAX_PORTS) {
       ingress_port_counter.count((bit<32> ) standard_metadata.ingress_port);