Fixed p4-14 programs not working on BMv2

The hack to deparse the packet_in breaks when using MAC addressess that
have many leading zeros (like in Mininet).

Change-Id: I509d98a21247903105cfb7d4206f8cc1a74acd3b
diff --git a/apps/pi-demo/ecmp/src/main/resources/ecmp_14.json b/apps/pi-demo/ecmp/src/main/resources/ecmp_14.json
index 78ebbe0..5b1b6d9 120000
--- a/apps/pi-demo/ecmp/src/main/resources/ecmp_14.json
+++ b/apps/pi-demo/ecmp/src/main/resources/ecmp_14.json
@@ -1 +1 @@
-../../../../../../tools/test/p4src/p4-16/p4c-out/ecmp.json
\ No newline at end of file
+../../../../../../tools/test/p4src/p4-14/p4c-out/ecmp.json
\ No newline at end of file
diff --git a/apps/pi-demo/ecmp/src/main/resources/ecmp_14.p4info b/apps/pi-demo/ecmp/src/main/resources/ecmp_14.p4info
index b4f5e4f..7fe1b6c 120000
--- a/apps/pi-demo/ecmp/src/main/resources/ecmp_14.p4info
+++ b/apps/pi-demo/ecmp/src/main/resources/ecmp_14.p4info
@@ -1 +1 @@
-../../../../../../tools/test/p4src/p4-16/p4c-out/ecmp.p4info
\ No newline at end of file
+../../../../../../tools/test/p4src/p4-14/p4c-out/ecmp.p4info
\ No newline at end of file
diff --git a/apps/pi-demo/ecmp/src/main/resources/ecmp_16.json b/apps/pi-demo/ecmp/src/main/resources/ecmp_16.json
new file mode 120000
index 0000000..78ebbe0
--- /dev/null
+++ b/apps/pi-demo/ecmp/src/main/resources/ecmp_16.json
@@ -0,0 +1 @@
+../../../../../../tools/test/p4src/p4-16/p4c-out/ecmp.json
\ No newline at end of file
diff --git a/apps/pi-demo/ecmp/src/main/resources/ecmp_16.p4info b/apps/pi-demo/ecmp/src/main/resources/ecmp_16.p4info
new file mode 120000
index 0000000..b4f5e4f
--- /dev/null
+++ b/apps/pi-demo/ecmp/src/main/resources/ecmp_16.p4info
@@ -0,0 +1 @@
+../../../../../../tools/test/p4src/p4-16/p4c-out/ecmp.p4info
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/resources/default.json b/drivers/bmv2/src/main/resources/default_16.json
similarity index 100%
rename from drivers/bmv2/src/main/resources/default.json
rename to drivers/bmv2/src/main/resources/default_16.json
diff --git a/drivers/bmv2/src/main/resources/default.p4info b/drivers/bmv2/src/main/resources/default_16.p4info
similarity index 100%
rename from drivers/bmv2/src/main/resources/default.p4info
rename to drivers/bmv2/src/main/resources/default_16.p4info
diff --git a/tools/test/p4src/p4-14/ecmp.p4 b/tools/test/p4src/p4-14/ecmp.p4
index 38962e6..0883ca7 100644
--- a/tools/test/p4src/p4-14/ecmp.p4
+++ b/tools/test/p4src/p4-14/ecmp.p4
@@ -32,8 +32,8 @@
     input {
         ecmp_hash_fields;
     }
-    algorithm : crc32;
-    output_width : 32;
+    algorithm : crc16;
+    output_width : 16;
 }
 
 action ecmp_group(group_id) {
diff --git a/tools/test/p4src/p4-14/include/parser.p4 b/tools/test/p4src/p4-14/include/parser.p4
index 0223297..f80620c 100644
--- a/tools/test/p4src/p4-14/include/parser.p4
+++ b/tools/test/p4src/p4-14/include/parser.p4
@@ -11,13 +11,19 @@
 header udp_t udp;
 
 parser start {
+    #ifdef __TOFINO_BUILD__
     // 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
+    // FIXME: This solution appears to be very brittle!!!
     return select(current(96, 8)) {
         0 : parse_pkt_in;
+    #else
+    return select(EGR_PORT_FIELD) {
+        CPU_PORT : parse_pkt_in;
         default  : default_parser;
     }
+    #endif
 }
 
 parser parse_pkt_in {
diff --git a/tools/test/p4src/p4-14/p4c-out/default.json b/tools/test/p4src/p4-14/p4c-out/default.json
index 8b6c72b..5248f7a 100644
--- a/tools/test/p4src/p4-14/p4c-out/default.json
+++ b/tools/test/p4src/p4-14/p4c-out/default.json
@@ -9,10 +9,8 @@
       "name" : "scalars_0",
       "id" : 0,
       "fields" : [
-        ["tmp_0", 104, false],
-        ["tmp", 8, false],
-        ["tmp_1", 32, false],
-        ["tmp_2", 32, false]
+        ["tmp", 32, false],
+        ["tmp_0", 32, false]
       ]
     },
     {
@@ -381,50 +379,10 @@
         {
           "name" : "start",
           "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"
-            }
-          ],
+          "parser_ops" : [],
           "transitions" : [
             {
-              "value" : "0x00",
+              "value" : "0x00ff",
               "mask" : null,
               "next_state" : "parse_pkt_in"
             },
@@ -437,7 +395,7 @@
           "transition_key" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
+              "value" : ["standard_metadata", "egress_spec"]
             }
           ]
         }
@@ -650,7 +608,7 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_1"]
+              "value" : ["scalars", "tmp"]
             },
             {
               "type" : "expression",
@@ -680,7 +638,7 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_1"]
+              "value" : ["scalars", "tmp"]
             }
           ],
           "source_info" : {
@@ -702,7 +660,7 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_2"]
+              "value" : ["scalars", "tmp_0"]
             },
             {
               "type" : "expression",
@@ -732,7 +690,7 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_2"]
+              "value" : ["scalars", "tmp_0"]
             }
           ],
           "source_info" : {
diff --git a/tools/test/p4src/p4-14/p4c-out/ecmp.json b/tools/test/p4src/p4-14/p4c-out/ecmp.json
index ba4f79b..60d929c 100644
--- a/tools/test/p4src/p4-14/p4c-out/ecmp.json
+++ b/tools/test/p4src/p4-14/p4c-out/ecmp.json
@@ -9,10 +9,8 @@
       "name" : "scalars_0",
       "id" : 0,
       "fields" : [
-        ["tmp_0", 104, false],
-        ["tmp", 8, false],
-        ["tmp_1", 32, false],
-        ["tmp_2", 32, false]
+        ["tmp", 32, false],
+        ["tmp_0", 32, false]
       ]
     },
     {
@@ -396,50 +394,10 @@
         {
           "name" : "start",
           "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"
-            }
-          ],
+          "parser_ops" : [],
           "transitions" : [
             {
-              "value" : "0x00",
+              "value" : "0x00ff",
               "mask" : null,
               "next_state" : "parse_pkt_in"
             },
@@ -452,7 +410,7 @@
           "transition_key" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
+              "value" : ["standard_metadata", "egress_spec"]
             }
           ]
         }
@@ -498,7 +456,7 @@
     {
       "name" : "calc",
       "id" : 0,
-      "algo" : "crc32",
+      "algo" : "crc16",
       "input" : [
         {
           "type" : "field",
@@ -633,7 +591,7 @@
             },
             {
               "type" : "hexstr",
-              "value" : "0x00000000"
+              "value" : "0x0000"
             },
             {
               "type" : "calculation",
@@ -641,7 +599,7 @@
             },
             {
               "type" : "hexstr",
-              "value" : "0x0000000000000002"
+              "value" : "0x00000002"
             }
           ],
           "source_info" : {
@@ -790,7 +748,7 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_1"]
+              "value" : ["scalars", "tmp"]
             },
             {
               "type" : "expression",
@@ -820,7 +778,7 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_1"]
+              "value" : ["scalars", "tmp"]
             }
           ],
           "source_info" : {
@@ -842,7 +800,7 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_2"]
+              "value" : ["scalars", "tmp_0"]
             },
             {
               "type" : "expression",
@@ -872,7 +830,7 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_2"]
+              "value" : ["scalars", "tmp_0"]
             }
           ],
           "source_info" : {
diff --git a/tools/test/p4src/p4-14/p4c-out/wcmp.json b/tools/test/p4src/p4-14/p4c-out/wcmp.json
index 8b272b0..be2bdec 100644
--- a/tools/test/p4src/p4-14/p4c-out/wcmp.json
+++ b/tools/test/p4src/p4-14/p4c-out/wcmp.json
@@ -9,10 +9,8 @@
       "name" : "scalars_0",
       "id" : 0,
       "fields" : [
-        ["tmp_0", 104, false],
-        ["tmp", 8, false],
-        ["tmp_1", 32, false],
-        ["tmp_2", 32, false]
+        ["tmp", 32, false],
+        ["tmp_0", 32, false]
       ]
     },
     {
@@ -397,50 +395,10 @@
         {
           "name" : "start",
           "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"
-            }
-          ],
+          "parser_ops" : [],
           "transitions" : [
             {
-              "value" : "0x00",
+              "value" : "0x00ff",
               "mask" : null,
               "next_state" : "parse_pkt_in"
             },
@@ -453,7 +411,7 @@
           "transition_key" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp"]
+              "value" : ["standard_metadata", "egress_spec"]
             }
           ]
         }
@@ -928,7 +886,7 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_1"]
+              "value" : ["scalars", "tmp"]
             },
             {
               "type" : "expression",
@@ -958,7 +916,7 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_1"]
+              "value" : ["scalars", "tmp"]
             }
           ],
           "source_info" : {
@@ -980,7 +938,7 @@
           "parameters" : [
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_2"]
+              "value" : ["scalars", "tmp_0"]
             },
             {
               "type" : "expression",
@@ -1010,7 +968,7 @@
             },
             {
               "type" : "field",
-              "value" : ["scalars", "tmp_2"]
+              "value" : ["scalars", "tmp_0"]
             }
           ],
           "source_info" : {