Merge branch 'master' into dev/auklet

Change-Id: Id2ee48db2f0df0a2966d065d941851c65fb12bf8
diff --git a/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java b/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java
index b66996d..1481c30 100644
--- a/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java
+++ b/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java
@@ -668,14 +668,14 @@
         //TODO handle MAC matching
         return flowEntry.selector().criteria().stream().allMatch(criterion -> {
             Criterion.Type type = criterion.type();
-            //If the critrion has IP we need to do LPM to establish matching.
+            //If the criterion has IP we need to do LPM to establish matching.
             if (type.equals(Criterion.Type.IPV4_SRC) || type.equals(Criterion.Type.IPV4_DST) ||
                     type.equals(Criterion.Type.IPV6_SRC) || type.equals(Criterion.Type.IPV6_DST)) {
                 IPCriterion ipCriterion = (IPCriterion) criterion;
                 IPCriterion matchCriterion = (IPCriterion) packet.getCriterion(ipCriterion.type());
-                //if the packet does not have an IPv4 or IPv6 criterion we return true
+                //if the packet does not have an IPv4 or IPv6 criterion we return false
                 if (matchCriterion == null) {
-                    return true;
+                    return false;
                 }
                 try {
                     Subnet subnet = Subnet.createInstance(ipCriterion.ip().toString());
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
index c7c7421..86c2908 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/PipeconfLoader.java
@@ -46,12 +46,13 @@
 @Component(immediate = true)
 public class PipeconfLoader {
 
-    private static final PiPipeconfId FABRIC_PIPECONF_ID =
+    public static final PiPipeconfId FABRIC_PIPECONF_ID =
             new PiPipeconfId("org.onosproject.pipelines.fabric");
+
     private static final String FABRIC_JSON_PATH = "/p4c-out/bmv2/fabric.json";
     private static final String FABRIC_P4INFO_PATH = "/p4c-out/bmv2/fabric.p4info";
 
-    public static final PiPipeconf FABRIC_PIPECONF = buildFabricPipeconf();
+    private static final PiPipeconf FABRIC_PIPECONF = buildFabricPipeconf();
 
     // XXX: Use a collection to hold only one pipeconf because we might separate
     // fabric pipeconf to leaf/spine pipeconf in the future.
@@ -84,8 +85,6 @@
                 .addBehaviour(PortStatisticsDiscovery.class, FabricPortStatisticsDiscovery.class)
                 .addExtension(P4_INFO_TEXT, p4InfoUrl)
                 .addExtension(BMV2_JSON, jsonUrl)
-                // Put here other target-specific extensions,
-                // e.g. Tofino's bin and context.json.
                 .build();
     }
 
diff --git a/pipelines/fabric/src/main/resources/Makefile b/pipelines/fabric/src/main/resources/Makefile
index e82fd31..c9557ef 100644
--- a/pipelines/fabric/src/main/resources/Makefile
+++ b/pipelines/fabric/src/main/resources/Makefile
@@ -1,8 +1,8 @@
 BMV2_CPU_PORT=255
 
-BMV2_OPTIONS=-DTARGET_BMV2
+BMV2_OPTIONS=-DTARGET_BMV2 -DCPU_PORT=$(BMV2_CPU_PORT)
 
-all: bmv2
+all: bmv2 bmv2-spgw
 
 bmv2:
 	p4c -v -x p4-16 -b bmv2-ss-p4org \
@@ -18,11 +18,5 @@
     		--p4runtime-file p4c-out/bmv2/fabric-spgw.p4info \
     		--p4runtime-format text fabric.p4
 
-custom:
-	p4c -v -x p4-16 -b $(BACKEND) \
-		$(BACKEND_OPTIONS) -o p4c-out/$(BACKEND) \
-		--p4runtime-file p4c-out/$(BACKEND)/fabric.p4info \
-		--p4runtime-format text fabric.p4
-
 clean:
 	rm -rf p4c-out/*
diff --git a/pipelines/fabric/src/main/resources/include/define.p4 b/pipelines/fabric/src/main/resources/include/define.p4
index f4e5b56..163c2ab 100644
--- a/pipelines/fabric/src/main/resources/include/define.p4
+++ b/pipelines/fabric/src/main/resources/include/define.p4
@@ -46,8 +46,8 @@
 
 const bit<4> IPV4_MIN_IHL = 5;
 
-#ifndef CPU_PORT
-const port_num_t CPU_PORT = 255;
+#ifndef _PKT_OUT_HDR_ANNOT_
+#define _PKT_OUT_HDR_ANNOT_
 #endif
 
 const fwd_type_t FWD_BRIDGING = 0;
diff --git a/pipelines/fabric/src/main/resources/include/header.p4 b/pipelines/fabric/src/main/resources/include/header.p4
index 0a0814e..7b61cec 100644
--- a/pipelines/fabric/src/main/resources/include/header.p4
+++ b/pipelines/fabric/src/main/resources/include/header.p4
@@ -25,6 +25,7 @@
     bit<7> _pad;
 }
 
+_PKT_OUT_HDR_ANNOT_
 @controller_header("packet_out")
 header packet_out_header_t {
     port_num_t egress_port;
diff --git a/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric-spgw.json b/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric-spgw.json
index 81b13e5..2e38cf5 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric-spgw.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric-spgw.json
@@ -1856,10 +1856,10 @@
             }
           ],
           "source_info" : {
-            "filename" : "include/control/../define.p4",
+            "filename" : "include/control/forwarding.p4",
             "line" : 50,
-            "column" : 28,
-            "source_fragment" : "255; ..."
+            "column" : 8,
+            "source_fragment" : "standard_metadata.egress_spec = 255"
           }
         }
       ]
@@ -6062,7 +6062,7 @@
             "filename" : "include/control/packetio.p4",
             "line" : 38,
             "column" : 12,
-            "source_fragment" : "standard_metadata.egress_port == CPU_PORT"
+            "source_fragment" : "standard_metadata.egress_port == 255"
           },
           "expression" : {
             "type" : "expression",
diff --git a/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric.json b/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric.json
index cdaefbc..228ff23 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/bmv2/fabric.json
@@ -71,22 +71,8 @@
       ]
     },
     {
-      "name" : "ipv6_t",
-      "id" : 5,
-      "fields" : [
-        ["version", 4, false],
-        ["traffic_class", 8, false],
-        ["flow_label", 20, false],
-        ["payload_len", 16, false],
-        ["next_hdr", 8, false],
-        ["hop_limit", 8, false],
-        ["src_addr", 128, false],
-        ["dst_addr", 128, false]
-      ]
-    },
-    {
       "name" : "arp_t",
-      "id" : 6,
+      "id" : 5,
       "fields" : [
         ["hw_type", 16, false],
         ["proto_type", 16, false],
@@ -97,7 +83,7 @@
     },
     {
       "name" : "tcp_t",
-      "id" : 7,
+      "id" : 6,
       "fields" : [
         ["src_port", 16, false],
         ["dst_port", 16, false],
@@ -114,7 +100,7 @@
     },
     {
       "name" : "udp_t",
-      "id" : 8,
+      "id" : 7,
       "fields" : [
         ["src_port", 16, false],
         ["dst_port", 16, false],
@@ -124,7 +110,7 @@
     },
     {
       "name" : "icmp_t",
-      "id" : 9,
+      "id" : 8,
       "fields" : [
         ["icmp_type", 8, false],
         ["icmp_code", 8, false],
@@ -136,7 +122,7 @@
     },
     {
       "name" : "packet_out_header_t",
-      "id" : 10,
+      "id" : 9,
       "fields" : [
         ["egress_port", 9, false],
         ["_pad", 7, false]
@@ -144,7 +130,7 @@
     },
     {
       "name" : "packet_in_header_t",
-      "id" : 11,
+      "id" : 10,
       "fields" : [
         ["ingress_port", 9, false],
         ["_pad", 7, false]
@@ -152,7 +138,7 @@
     },
     {
       "name" : "standard_metadata",
-      "id" : 12,
+      "id" : 11,
       "fields" : [
         ["ingress_port", 9, false],
         ["egress_spec", 9, false],
@@ -220,50 +206,43 @@
       "pi_omit" : true
     },
     {
-      "name" : "ipv6",
-      "id" : 6,
-      "header_type" : "ipv6_t",
-      "metadata" : false,
-      "pi_omit" : true
-    },
-    {
       "name" : "arp",
-      "id" : 7,
+      "id" : 6,
       "header_type" : "arp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "tcp",
-      "id" : 8,
+      "id" : 7,
       "header_type" : "tcp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "udp",
-      "id" : 9,
+      "id" : 8,
       "header_type" : "udp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "icmp",
-      "id" : 10,
+      "id" : 9,
       "header_type" : "icmp_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "packet_out",
-      "id" : 11,
+      "id" : 10,
       "header_type" : "packet_out_header_t",
       "metadata" : false,
       "pi_omit" : true
     },
     {
       "name" : "packet_in",
-      "id" : 12,
+      "id" : 11,
       "header_type" : "packet_in_header_t",
       "metadata" : false,
       "pi_omit" : true
@@ -694,7 +673,7 @@
       "id" : 0,
       "source_info" : {
         "filename" : "include/parser.p4",
-        "line" : 166,
+        "line" : 164,
         "column" : 8,
         "source_fragment" : "FabricDeparser"
       },
@@ -1396,10 +1375,10 @@
             }
           ],
           "source_info" : {
-            "filename" : "include/control/../define.p4",
+            "filename" : "include/control/forwarding.p4",
             "line" : 50,
-            "column" : 28,
-            "source_fragment" : "255; ..."
+            "column" : 8,
+            "source_fragment" : "standard_metadata.egress_spec = 255"
           }
         }
       ]
@@ -3635,7 +3614,7 @@
       "id" : 1,
       "source_info" : {
         "filename" : "fabric.p4",
-        "line" : 60,
+        "line" : 62,
         "column" : 8,
         "source_fragment" : "FabricEgress"
       },
@@ -3674,7 +3653,7 @@
             "filename" : "include/control/packetio.p4",
             "line" : 38,
             "column" : 12,
-            "source_fragment" : "standard_metadata.egress_port == CPU_PORT"
+            "source_fragment" : "standard_metadata.egress_port == 255"
           },
           "expression" : {
             "type" : "expression",
diff --git a/tools/dev/p4vm/install-p4-tools.sh b/tools/dev/p4vm/install-p4-tools.sh
index 00f1b4b..fb88e7e 100755
--- a/tools/dev/p4vm/install-p4-tools.sh
+++ b/tools/dev/p4vm/install-p4-tools.sh
@@ -22,6 +22,7 @@
 GRPC_COMMIT="tags/v1.3.2"
 LIBYANG_COMMIT="v0.14-r1"
 SYSREPO_COMMIT="v0.7.2"
+P4RT_TEST_COMMIT="master"
 
 NUM_CORES=`grep -c ^processor /proc/cpuinfo`
 
@@ -259,6 +260,18 @@
     sudo ldconfig
 }
 
+function do_p4rt_test {
+    cd ${BUILD_DIR}
+    if [ ! -d p4rt-test ]; then
+        git clone https://github.com/TakeshiTseng/P4-runtime-test-tool.git p4rt-test
+    fi
+    cd p4rt-test
+    git pull origin master
+
+    sudo rm -f /usr/local/bin/p4rt-test
+    sudo ln -s ${BUILD_DIR}/p4rt-test/main.py /usr/local/bin/p4rt-test
+}
+
 function check_commit {
     if [ ! -e $2 ]; then
         return 0 # true
@@ -287,6 +300,7 @@
     func_name="$3"
     simple_name="$4"
     if ${MUST_DO_ALL} = true \
+        || ${commit_id} = "master" \
         || check_commit ${commit_id} ${proj_dir}/.last_built_commit; then
         echo "#"
         echo "# Building ${simple_name} (${commit_id})"
@@ -330,5 +344,6 @@
 check_and_do ${PI_COMMIT} p4runtime do_p4runtime p4runtime
 check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 bmv2
 check_and_do ${P4C_COMMIT} p4c do_p4c p4c
+check_and_do ${P4RT_TEST_COMMIT} p4rt-test do_p4rt_test p4rt-test
 
 echo "Done!"
diff --git a/tools/dev/p4vm/pre-ova-cleanup.sh b/tools/dev/p4vm/pre-ova-cleanup.sh
index 3ea45e1..dcfecc9 100755
--- a/tools/dev/p4vm/pre-ova-cleanup.sh
+++ b/tools/dev/p4vm/pre-ova-cleanup.sh
@@ -17,4 +17,4 @@
 
 cat /dev/null > ~/.bash_history
 
-poweroff
+sudo poweroff