New P4RuntimeClient implementation that supports batching and error reporting

The new client API supports batching and provides detailed response for
write requests (e.g. if entity already exists when inserting), which was
not possible with the old one.

This patch includes:
- New more efficient implementation of P4RuntimeClient (no more locking,
use native gRPC executor, use stub deadlines)
- Ported all codecs to new AbstractCodec-based implementation (needed to
implement codec cache in the future)
- Uses batching in P4RuntimeFlowRuleProgrammable and
P4RuntimeGroupActionProgrammable
- Minor changes to PI framework runtime classes

Change-Id: I3fac42057bb4e1389d761006a32600c786598683
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
index 9ecc65f..882a624 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
@@ -19,7 +19,7 @@
 import org.onosproject.net.pi.model.PiActionId;
 import org.onosproject.net.pi.model.PiActionParamId;
 import org.onosproject.net.pi.model.PiActionProfileId;
-import org.onosproject.net.pi.model.PiControlMetadataId;
+import org.onosproject.net.pi.model.PiPacketMetadataId;
 import org.onosproject.net.pi.model.PiCounterId;
 import org.onosproject.net.pi.model.PiMatchFieldId;
 import org.onosproject.net.pi.model.PiTableId;
@@ -254,8 +254,8 @@
     public static final PiActionProfileId FABRIC_INGRESS_NEXT_HASHED_SELECTOR =
             PiActionProfileId.of("FabricIngress.next.hashed_selector");
     // Packet Metadata IDs
-    public static final PiControlMetadataId INGRESS_PORT =
-            PiControlMetadataId.of("ingress_port");
-    public static final PiControlMetadataId EGRESS_PORT =
-            PiControlMetadataId.of("egress_port");
+    public static final PiPacketMetadataId INGRESS_PORT =
+            PiPacketMetadataId.of("ingress_port");
+    public static final PiPacketMetadataId EGRESS_PORT =
+            PiPacketMetadataId.of("egress_port");
 }
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
index 580d6f7..e523472 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
@@ -37,7 +37,7 @@
 import org.onosproject.net.pi.model.PiPipelineInterpreter;
 import org.onosproject.net.pi.model.PiTableId;
 import org.onosproject.net.pi.runtime.PiAction;
-import org.onosproject.net.pi.runtime.PiControlMetadata;
+import org.onosproject.net.pi.runtime.PiPacketMetadata;
 import org.onosproject.net.pi.runtime.PiPacketOperation;
 
 import java.nio.ByteBuffer;
@@ -172,19 +172,18 @@
     private PiPacketOperation createPiPacketOperation(
             DeviceId deviceId, ByteBuffer data, long portNumber)
             throws PiInterpreterException {
-        PiControlMetadata metadata = createPacketMetadata(portNumber);
+        PiPacketMetadata metadata = createPacketMetadata(portNumber);
         return PiPacketOperation.builder()
-                .forDevice(deviceId)
                 .withType(PACKET_OUT)
                 .withData(copyFrom(data))
                 .withMetadatas(ImmutableList.of(metadata))
                 .build();
     }
 
-    private PiControlMetadata createPacketMetadata(long portNumber)
+    private PiPacketMetadata createPacketMetadata(long portNumber)
             throws PiInterpreterException {
         try {
-            return PiControlMetadata.builder()
+            return PiPacketMetadata.builder()
                     .withId(FabricConstants.EGRESS_PORT)
                     .withValue(copyFrom(portNumber).fit(PORT_BITWIDTH))
                     .build();
@@ -233,10 +232,9 @@
     }
 
     @Override
-    public InboundPacket mapInboundPacket(PiPacketOperation packetIn) throws PiInterpreterException {
+    public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
         // Assuming that the packet is ethernet, which is fine since fabric.p4
         // can deparse only ethernet packets.
-        DeviceId deviceId = packetIn.deviceId();
         Ethernet ethPkt;
         try {
             ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0,
@@ -246,7 +244,7 @@
         }
 
         // Returns the ingress port packet metadata.
-        Optional<PiControlMetadata> packetMetadata = packetIn.metadatas()
+        Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas()
                 .stream().filter(m -> m.id().equals(FabricConstants.INGRESS_PORT))
                 .findFirst();