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/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketOutCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketOutCodec.java
new file mode 100644
index 0000000..6d020c3
--- /dev/null
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketOutCodec.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.p4runtime.ctl.codec;
+
+import com.google.protobuf.ByteString;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.runtime.PiPacketOperation;
+import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser;
+import p4.config.v1.P4InfoOuterClass;
+import p4.v1.P4RuntimeOuterClass;
+
+import static org.onosproject.p4runtime.ctl.codec.Codecs.CODECS;
+
+/**
+ * Codec for P4Runtime PacketOut. Only encoding is supported, as decoding is not
+ * meaningful in this case (packet-outs are always generated by the client).
+ */
+public final class PacketOutCodec
+        extends AbstractCodec<PiPacketOperation,
+        P4RuntimeOuterClass.PacketOut, Object> {
+
+    private static final String PACKET_OUT = "packet_out";
+
+    @Override
+    protected P4RuntimeOuterClass.PacketOut encode(
+            PiPacketOperation piPacket, Object ignored, PiPipeconf pipeconf,
+            P4InfoBrowser browser)
+            throws CodecException, P4InfoBrowser.NotFoundException {
+        final P4InfoOuterClass.Preamble ctrlPktMetaPreamble = browser
+                .controllerPacketMetadatas()
+                .getByName(PACKET_OUT)
+                .getPreamble();
+        return P4RuntimeOuterClass.PacketOut.newBuilder()
+                .addAllMetadata(CODECS.packetMetadata().encodeAll(
+                        piPacket.metadatas(), ctrlPktMetaPreamble, pipeconf))
+                .setPayload(ByteString.copyFrom(piPacket.data().asReadOnlyBuffer()))
+                .build();
+
+    }
+
+    @Override
+    protected PiPacketOperation decode(
+            P4RuntimeOuterClass.PacketOut message, Object ignored,
+            PiPipeconf pipeconf, P4InfoBrowser browser)
+            throws CodecException {
+        throw new CodecException("Decoding of packet-out is not supported");
+    }
+}