[ONOS-7808] Support P4Runtime default table entries

We achieve this by creating a special mirror to store the original
default entries as specified in the P4 program. Applications can modify
the default entry by inserting flow rules with empty selectors. When
removing such flow rule, the default table entry is restored to the
original one as stored in the mirror.

Change-Id: Ib11a7172ab56be7cbbd23022e4b62ed6b70b6eca
diff --git a/pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslator.java b/pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslator.java
index 1d7d5c0..2cb7ba5 100644
--- a/pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslator.java
+++ b/pipelines/fabric/impl/src/main/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslator.java
@@ -19,9 +19,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
-import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.DeviceId;
@@ -71,8 +69,6 @@
 
     //FIXME: Max number supported by PI
     static final int CLONE_TO_CPU_ID = 511;
-    private static final List<String> DEFAULT_ROUTE_PREFIXES = Lists.newArrayList(
-            "0.0.0.0/1", "128.0.0.0/1");
 
     private static final Set<Criterion.Type> ACL_CRITERIA = ImmutableSet.of(
             Criterion.Type.IN_PORT,
@@ -233,14 +229,12 @@
     private void defaultIpv4Route(ForwardingObjective obj,
                                   ObjectiveTranslation.Builder resultBuilder)
             throws FabricPipelinerException {
-
-        // Hack to work around the inability to program default rules.
-        for (String prefix : DEFAULT_ROUTE_PREFIXES) {
-            final TrafficSelector selector = DefaultTrafficSelector.builder()
-                    .matchIPDst(IpPrefix.valueOf(prefix)).build();
-            resultBuilder.addFlowRule(flowRule(
-                    obj, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, selector));
-        }
+        ForwardingObjective defaultObj = obj.copy()
+                .withPriority(0)
+                .add();
+        final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
+        resultBuilder.addFlowRule(flowRule(
+                defaultObj, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, selector));
     }
 
     private void mplsRule(ForwardingObjective obj, Set<Criterion> criteriaWithMeta,
diff --git a/pipelines/fabric/impl/src/main/resources/include/control/forwarding.p4 b/pipelines/fabric/impl/src/main/resources/include/control/forwarding.p4
index 7348c59..9b1e523 100644
--- a/pipelines/fabric/impl/src/main/resources/include/control/forwarding.p4
+++ b/pipelines/fabric/impl/src/main/resources/include/control/forwarding.p4
@@ -114,7 +114,7 @@
             nop_routing_v4;
             @defaultonly nop;
         }
-        const default_action = nop();
+        default_action = nop();
 #ifdef WTIH_DEBUG
         counters = routing_v4_counter;
 #endif // WITH_DEBUG
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/bmv2.json b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/bmv2.json
index 502ccc9..75f6465 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/bmv2.json
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/bmv2.json
@@ -4516,9 +4516,9 @@
           },
           "default_entry" : {
             "action_id" : 4,
-            "action_const" : true,
+            "action_const" : false,
             "action_data" : [],
-            "action_entry_const" : true
+            "action_entry_const" : false
           }
         },
         {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/p4info.txt b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/p4info.txt
index c82e3bf..e034147 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/p4info.txt
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-bng/bmv2/default/p4info.txt
@@ -311,7 +311,6 @@
     annotations: "@defaultonly"
     scope: DEFAULT_ONLY
   }
-  const_default_action_id: 16819938
   size: 1024
 }
 tables {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json
index 83da36b..e300f55 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/bmv2.json
@@ -15945,9 +15945,9 @@
           },
           "default_entry" : {
             "action_id" : 8,
-            "action_const" : true,
+            "action_const" : false,
             "action_data" : [],
-            "action_entry_const" : true
+            "action_entry_const" : false
           }
         },
         {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt
index 7ea857e..c5601203 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-full/bmv2/default/p4info.txt
@@ -469,7 +469,6 @@
     annotations: "@defaultonly"
     scope: DEFAULT_ONLY
   }
-  const_default_action_id: 16819938
   size: 1024
 }
 tables {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json
index a56d4aa..95eb58e 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/bmv2.json
@@ -10180,9 +10180,9 @@
           },
           "default_entry" : {
             "action_id" : 3,
-            "action_const" : true,
+            "action_const" : false,
             "action_data" : [],
-            "action_entry_const" : true
+            "action_entry_const" : false
           }
         },
         {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt
index b3f3a9d..f7197d7 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-int/bmv2/default/p4info.txt
@@ -182,7 +182,6 @@
     annotations: "@defaultonly"
     scope: DEFAULT_ONLY
   }
-  const_default_action_id: 16819938
   size: 1024
 }
 tables {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json
index 1e044cc..f98e55d 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/bmv2.json
@@ -12260,9 +12260,9 @@
           },
           "default_entry" : {
             "action_id" : 5,
-            "action_const" : true,
+            "action_const" : false,
             "action_data" : [],
-            "action_entry_const" : true
+            "action_entry_const" : false
           }
         },
         {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt
index 4127ca9..fb934e7 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw-int/bmv2/default/p4info.txt
@@ -224,7 +224,6 @@
     annotations: "@defaultonly"
     scope: DEFAULT_ONLY
   }
-  const_default_action_id: 16819938
   size: 1024
 }
 tables {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json
index c8cfde6..70412de 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json
@@ -5170,9 +5170,9 @@
           },
           "default_entry" : {
             "action_id" : 4,
-            "action_const" : true,
+            "action_const" : false,
             "action_data" : [],
-            "action_entry_const" : true
+            "action_entry_const" : false
           }
         },
         {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt
index fa68a8d..4f65f90 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt
@@ -200,7 +200,6 @@
     annotations: "@defaultonly"
     scope: DEFAULT_ONLY
   }
-  const_default_action_id: 16819938
   size: 1024
 }
 tables {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json
index bdab9d8..828e0a3 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json
@@ -3101,9 +3101,9 @@
           },
           "default_entry" : {
             "action_id" : 2,
-            "action_const" : true,
+            "action_const" : false,
             "action_data" : [],
-            "action_entry_const" : true
+            "action_entry_const" : false
           }
         },
         {
diff --git a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt
index 7507ab9..9e5cef9 100644
--- a/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt
+++ b/pipelines/fabric/impl/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt
@@ -158,7 +158,6 @@
     annotations: "@defaultonly"
     scope: DEFAULT_ONLY
   }
-  const_default_action_id: 16819938
   size: 1024
 }
 tables {