Add support for P4Runtime clone sessions via Group API

Clone sessions can now be created by defining groups with new type CLONE

The PI framework has been refactored to abstract commonality between
multicast groups and clone sessions as both are managed as part of the
P4Runtime packet replication engine (PRE).

Change-Id: I2f23c629b7de1931d5cab96ec76aef26130ce418
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCloneSessionEntry.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCloneSessionEntry.java
new file mode 100644
index 0000000..656a809
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCloneSessionEntry.java
@@ -0,0 +1,242 @@
+/*
+ * 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.net.pi.runtime;
+
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.DeviceId;
+
+import java.util.Collection;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a clone session entry of a protocol-independent packet
+ * replication engine (PRE).
+ */
+@Beta
+public final class PiCloneSessionEntry implements PiPreEntry {
+
+    public static final int DEFAULT_CLASS_OF_SERVICE = 0;
+    public static final int DO_NOT_TRUNCATE = 0;
+
+    private final int sessionId;
+    private final Set<PiPreReplica> replicas;
+    private final int classOfService;
+    private final int maxPacketLengthBytes;
+
+    private PiCloneSessionEntry(int sessionId, Set<PiPreReplica> replicas,
+                                int classOfService, int maxPacketBytes) {
+        this.sessionId = sessionId;
+        this.replicas = replicas;
+        this.classOfService = classOfService;
+        this.maxPacketLengthBytes = maxPacketBytes;
+    }
+
+    /**
+     * Returns the identifier of this clone session, unique in the scope of a
+     * PRE instance.
+     *
+     * @return clone session ID
+     */
+    public int sessionId() {
+        return sessionId;
+    }
+
+    /**
+     * Returns the packet replicas provided by this clone session.
+     *
+     * @return packet replicas
+     */
+    public Set<PiPreReplica> replicas() {
+        return replicas;
+    }
+
+    /**
+     * Returns the class of service associated to the replicas produced by this
+     * clone session.
+     *
+     * @return class of service
+     */
+    public int classOfService() {
+        return classOfService;
+    }
+
+    /**
+     * Returns the maximum length in bytes of cloned packets. If a larger packet
+     * is cloned, then the PRE is expected to truncate clones to the given size.
+     * 0 means that no truncation on the clone(s) will be performed.
+     *
+     * @return maximum length in bytes of clones packets
+     */
+    public int maxPacketLengthBytes() {
+        return maxPacketLengthBytes;
+    }
+
+    @Override
+    public PiEntityType piEntityType() {
+        return PiEntityType.PRE_ENTRY;
+    }
+
+    @Override
+    public PiPreEntryType preEntryType() {
+        return PiPreEntryType.CLONE_SESSION;
+    }
+
+    @Override
+    public PiCloneSessionEntryHandle handle(DeviceId deviceId) {
+        return PiCloneSessionEntryHandle.of(deviceId, this);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(sessionId, replicas, classOfService,
+                                maxPacketLengthBytes);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final PiCloneSessionEntry other = (PiCloneSessionEntry) obj;
+        return Objects.equal(this.sessionId, other.sessionId)
+                && Objects.equal(this.replicas, other.replicas)
+                && Objects.equal(this.classOfService, other.classOfService)
+                && Objects.equal(this.maxPacketLengthBytes, other.maxPacketLengthBytes);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("sessionId", sessionId)
+                .add("replicas", replicas)
+                .add("classOfService", classOfService)
+                .add("maxPacketLengthBytes", maxPacketLengthBytes)
+                .toString();
+    }
+
+    /**
+     * Returns a new builder of clone session entries.
+     *
+     * @return builder
+     */
+    public static PiCloneSessionEntry.Builder builder() {
+        return new PiCloneSessionEntry.Builder();
+    }
+
+    /**
+     * Builder of PI clone session entries.
+     */
+    public static final class Builder {
+
+        private Integer sessionId;
+        private ImmutableSet.Builder<PiPreReplica> replicaSetBuilder = ImmutableSet.builder();
+        private int classOfService = DEFAULT_CLASS_OF_SERVICE;
+        private int maxPacketLengthBytes = DO_NOT_TRUNCATE;
+
+        private Builder() {
+            // Hide constructor.
+        }
+
+        /**
+         * Sets the identifier of this clone session.
+         *
+         * @param sessionId session ID
+         * @return this
+         */
+        public PiCloneSessionEntry.Builder withSessionId(int sessionId) {
+            this.sessionId = sessionId;
+            return this;
+        }
+
+        /**
+         * Adds the given packet replica to this clone session.
+         *
+         * @param replica packet replica
+         * @return this
+         */
+        public PiCloneSessionEntry.Builder addReplica(PiPreReplica replica) {
+            checkNotNull(replica);
+            replicaSetBuilder.add(replica);
+            return this;
+        }
+
+        /**
+         * Adds the given packet replicas to this clone session.
+         *
+         * @param replicas packet replicas
+         * @return this
+         */
+        public PiCloneSessionEntry.Builder addReplicas(Collection<PiPreReplica> replicas) {
+            checkNotNull(replicas);
+            replicaSetBuilder.addAll(replicas);
+            return this;
+        }
+
+        /**
+         * Sets the class of service of this clone session. If not set, the
+         * default value {@link PiCloneSessionEntry#DEFAULT_CLASS_OF_SERVICE}
+         * will be used.
+         *
+         * @param classOfService class of service value
+         * @return this
+         */
+        public PiCloneSessionEntry.Builder withClassOfService(
+                int classOfService) {
+            this.classOfService = classOfService;
+            return this;
+        }
+
+        /**
+         * Sets the maximum length in bytes of cloned packets. If not set, the
+         * default value {@link PiCloneSessionEntry#DO_NOT_TRUNCATE} will be
+         * used.
+         *
+         * @param maxPacketLengthBytes max length in bytes of cloned packets
+         * @return this
+         */
+        public PiCloneSessionEntry.Builder withMaxPacketLengthBytes(
+                int maxPacketLengthBytes) {
+            checkArgument(maxPacketLengthBytes >= 0,
+                          "maxPacketLengthBytes must be a positive integer");
+            this.maxPacketLengthBytes = maxPacketLengthBytes;
+            return this;
+        }
+
+        /**
+         * Returns a new clone session entry.
+         *
+         * @return clone session entry
+         */
+        public PiCloneSessionEntry build() {
+            checkNotNull(sessionId, "Clone session ID must be set");
+            final ImmutableSet<PiPreReplica> replicas = replicaSetBuilder.build();
+            return new PiCloneSessionEntry(
+                    sessionId, replicas, classOfService, maxPacketLengthBytes);
+        }
+    }
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCloneSessionEntryHandle.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCloneSessionEntryHandle.java
new file mode 100644
index 0000000..cd2df4a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCloneSessionEntryHandle.java
@@ -0,0 +1,105 @@
+/*
+ * 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.net.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import org.onosproject.net.DeviceId;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Global identifier of a PI clone session entry applied to the packet
+ * replication engine (PRE) of a device, uniquely defined by a device ID, and
+ * session ID.
+ */
+@Beta
+public final class PiCloneSessionEntryHandle extends PiPreEntryHandle {
+
+    private final int sessionId;
+
+    private PiCloneSessionEntryHandle(DeviceId deviceId, int sessionId) {
+        super(deviceId);
+        this.sessionId = sessionId;
+    }
+
+    /**
+     * Creates a new handle for the given device ID and PI clone session ID.
+     *
+     * @param deviceId  device ID
+     * @param sessionId clone session ID
+     * @return PI clone session entry handle
+     */
+    public static PiCloneSessionEntryHandle of(DeviceId deviceId,
+                                               int sessionId) {
+        return new PiCloneSessionEntryHandle(deviceId, sessionId);
+    }
+
+    /**
+     * Creates a new handle for the given device ID and PI clone session entry.
+     *
+     * @param deviceId device ID
+     * @param entry    PI clone session entry
+     * @return PI clone session entry handle
+     */
+    public static PiCloneSessionEntryHandle of(DeviceId deviceId,
+                                               PiCloneSessionEntry entry) {
+        checkNotNull(entry);
+        return new PiCloneSessionEntryHandle(deviceId, entry.sessionId());
+    }
+
+    /**
+     * Returns the clone session ID associated with this handle.
+     *
+     * @return session ID
+     */
+    public int sessionId() {
+        return sessionId;
+    }
+
+    @Override
+    public PiPreEntryType preEntryType() {
+        return PiPreEntryType.CLONE_SESSION;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(deviceId(), sessionId);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        PiCloneSessionEntryHandle that = (PiCloneSessionEntryHandle) o;
+        return Objects.equal(deviceId(), that.deviceId()) &&
+                Objects.equal(sessionId, that.sessionId);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("deviceId", deviceId())
+                .add("sessionId", sessionId)
+                .toString();
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiEntityType.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiEntityType.java
index 0e99188..2dc7235 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiEntityType.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiEntityType.java
@@ -54,14 +54,9 @@
     COUNTER_CELL("counter cell"),
 
     /**
-     * Packet Replication Engine (PRE) multicast group entry.
+     * Packet Replication Engine (PRE) entry.
      */
-    PRE_MULTICAST_GROUP_ENTRY("PRE multicast group entry"),
-
-    /**
-     * Packet Replication Engine (PRE) clone session entry.
-     */
-    PRE_CLONE_SESSION_ENTRY("PRE clone session entry");
+    PRE_ENTRY("PRE entry");
 
     private final String humanReadableName;
 
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntry.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntry.java
index 7a833aa..73898f5 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntry.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntry.java
@@ -68,7 +68,7 @@
 
     @Override
     public PiEntityType piEntityType() {
-        return PiEntityType.PRE_MULTICAST_GROUP_ENTRY;
+        return PiEntityType.PRE_ENTRY;
     }
 
     @Override
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntryHandle.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntryHandle.java
index b74ca8e..b18cb51 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntryHandle.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMulticastGroupEntryHandle.java
@@ -29,7 +29,7 @@
  * ID.
  */
 @Beta
-public final class PiMulticastGroupEntryHandle extends PiHandle {
+public final class PiMulticastGroupEntryHandle extends PiPreEntryHandle {
 
     private final int groupId;
 
@@ -74,8 +74,8 @@
     }
 
     @Override
-    public PiEntityType entityType() {
-        return PiEntityType.PRE_MULTICAST_GROUP_ENTRY;
+    public PiPreEntryType preEntryType() {
+        return PiPreEntryType.MULTICAST_GROUP;
     }
 
     @Override
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntry.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntry.java
index fb6c5e0..a774ff9 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntry.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntry.java
@@ -26,20 +26,6 @@
 public interface PiPreEntry extends PiEntity {
 
     /**
-     * Type of PRE entry.
-     */
-    enum PiPreEntryType {
-        /**
-         * Multicast group entry.
-         */
-        MULTICAST_GROUP,
-        /**
-         * Clone session entry.
-         */
-        CLONE_SESSION
-    }
-
-    /**
      * Returns the type of this PRE entry.
      *
      * @return PRE entry type
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntryHandle.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntryHandle.java
new file mode 100644
index 0000000..e159593
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntryHandle.java
@@ -0,0 +1,41 @@
+/*
+ * 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.net.pi.runtime;
+
+import org.onosproject.net.DeviceId;
+
+/**
+ * Abstract implementation of a PI handle for PRE entries.
+ */
+public abstract class PiPreEntryHandle extends PiHandle {
+
+    PiPreEntryHandle(DeviceId deviceId) {
+        super(deviceId);
+    }
+
+    /**
+     * Returns the type of PRE entry associated with this handle.
+     *
+     * @return PRE entry type
+     */
+    public abstract PiPreEntryType preEntryType();
+
+    @Override
+    public PiEntityType entityType() {
+        return PiEntityType.PRE_ENTRY;
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntryType.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntryType.java
new file mode 100644
index 0000000..4448834
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiPreEntryType.java
@@ -0,0 +1,32 @@
+/*
+ * 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.net.pi.runtime;
+
+/**
+ * Type of entry of the packet replication engine (PRE) or a
+ * protocol-independent pipeline.
+ */
+public enum PiPreEntryType {
+    /**
+     * Multicast group entry.
+     */
+    MULTICAST_GROUP,
+    /**
+     * Clone session entry.
+     */
+    CLONE_SESSION
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/service/PiMulticastGroupTranslationStore.java b/core/api/src/main/java/org/onosproject/net/pi/service/PiReplicationGroupTranslationStore.java
similarity index 78%
rename from core/api/src/main/java/org/onosproject/net/pi/service/PiMulticastGroupTranslationStore.java
rename to core/api/src/main/java/org/onosproject/net/pi/service/PiReplicationGroupTranslationStore.java
index f961d84..60ef15c 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/service/PiMulticastGroupTranslationStore.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/service/PiReplicationGroupTranslationStore.java
@@ -18,13 +18,13 @@
 
 import com.google.common.annotations.Beta;
 import org.onosproject.net.group.Group;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiPreEntry;
 
 /**
  * A PI translation store that keeps track of which groups have been
- * translated to which PI PRE multicast groups.
+ * translated to which PI packet replication engine (PRE) entry.
  */
 @Beta
-public interface PiMulticastGroupTranslationStore
-        extends PiTranslationStore<Group, PiMulticastGroupEntry> {
+public interface PiReplicationGroupTranslationStore
+        extends PiTranslationStore<Group, PiPreEntry> {
 }
diff --git a/core/api/src/main/java/org/onosproject/net/pi/service/PiMulticastGroupTranslator.java b/core/api/src/main/java/org/onosproject/net/pi/service/PiReplicationGroupTranslator.java
similarity index 75%
rename from core/api/src/main/java/org/onosproject/net/pi/service/PiMulticastGroupTranslator.java
rename to core/api/src/main/java/org/onosproject/net/pi/service/PiReplicationGroupTranslator.java
index e687189..960f98e 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/service/PiMulticastGroupTranslator.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/service/PiReplicationGroupTranslator.java
@@ -18,12 +18,13 @@
 
 import com.google.common.annotations.Beta;
 import org.onosproject.net.group.Group;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiPreEntry;
 
 /**
- * A translator of groups to PI multicast group.
+ * A translator of groups for packet replication to PI packet replication engine
+ * (PRE) entries.
  */
 @Beta
-public interface PiMulticastGroupTranslator
-        extends PiTranslator<Group, PiMulticastGroupEntry> {
+public interface PiReplicationGroupTranslator
+        extends PiTranslator<Group, PiPreEntry> {
 }
diff --git a/core/api/src/main/java/org/onosproject/net/pi/service/PiTranslationService.java b/core/api/src/main/java/org/onosproject/net/pi/service/PiTranslationService.java
index 20ea14d..4871140 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/service/PiTranslationService.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/service/PiTranslationService.java
@@ -48,9 +48,9 @@
 
     /**
      * Returns a group translator for packet replication engine (PRE)
-     * multicast groups.
+     * entries.
      *
-     * @return multicast group translator
+     * @return replication group translator
      */
-    PiMulticastGroupTranslator multicastGroupTranslator();
+    PiReplicationGroupTranslator replicationGroupTranslator();
 }
diff --git a/core/net/src/main/java/org/onosproject/net/pi/impl/PiMulticastGroupTranslatorImpl.java b/core/net/src/main/java/org/onosproject/net/pi/impl/PiReplicationGroupTranslatorImpl.java
similarity index 79%
rename from core/net/src/main/java/org/onosproject/net/pi/impl/PiMulticastGroupTranslatorImpl.java
rename to core/net/src/main/java/org/onosproject/net/pi/impl/PiReplicationGroupTranslatorImpl.java
index 7d48209..1f562a4 100644
--- a/core/net/src/main/java/org/onosproject/net/pi/impl/PiMulticastGroupTranslatorImpl.java
+++ b/core/net/src/main/java/org/onosproject/net/pi/impl/PiReplicationGroupTranslatorImpl.java
@@ -26,7 +26,9 @@
 import org.onosproject.net.group.GroupDescription;
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.model.PiPipelineInterpreter;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntry;
 import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiPreEntry;
 import org.onosproject.net.pi.runtime.PiPreReplica;
 import org.onosproject.net.pi.service.PiTranslationException;
 
@@ -41,19 +43,20 @@
 import static java.lang.String.format;
 
 /**
- * Implementation of multicast group translation logic.
+ * Implementation of replication group translation logic.
  */
-final class PiMulticastGroupTranslatorImpl {
+final class PiReplicationGroupTranslatorImpl {
 
-    private PiMulticastGroupTranslatorImpl() {
+    private PiReplicationGroupTranslatorImpl() {
         // Hides constructor.
     }
 
     /**
-     * Returns a PI PRE multicast group entry equivalent to the given group, for
-     * the given pipeconf and device.
+     * Returns a PI PRE entry equivalent to the given group, for the given
+     * pipeconf and device.
      * <p>
-     * The passed group is expected to have type {@link GroupDescription.Type#ALL}.
+     * The passed group is expected to have type {@link GroupDescription.Type#ALL}
+     * or {@link GroupDescription.Type#CLONE}.
      *
      * @param group    group
      * @param pipeconf pipeconf
@@ -61,16 +64,11 @@
      * @return PI PRE entry
      * @throws PiTranslationException if the group cannot be translated
      */
-    static PiMulticastGroupEntry translate(Group group, PiPipeconf pipeconf, Device device)
+    static PiPreEntry translate(Group group, PiPipeconf pipeconf, Device device)
             throws PiTranslationException {
 
         checkNotNull(group);
 
-        if (!group.type().equals(GroupDescription.Type.ALL)) {
-            throw new PiTranslationException(format(
-                    "group type %s not supported", group.type()));
-        }
-
         final List<Instruction> instructions = group.buckets().buckets().stream()
                 .flatMap(b -> b.treatment().allInstructions().stream())
                 .collect(Collectors.toList());
@@ -88,10 +86,21 @@
                 .map(i -> (OutputInstruction) i)
                 .collect(Collectors.toList());
 
-        return PiMulticastGroupEntry.builder()
-                .withGroupId(group.id().id())
-                .addReplicas(getReplicas(outInstructions, device))
-                .build();
+        switch (group.type()) {
+            case ALL:
+                return PiMulticastGroupEntry.builder()
+                        .withGroupId(group.id().id())
+                        .addReplicas(getReplicas(outInstructions, device))
+                        .build();
+            case CLONE:
+                return PiCloneSessionEntry.builder()
+                        .withSessionId(group.id().id())
+                        .addReplicas(getReplicas(outInstructions, device))
+                        .build();
+            default:
+                throw new PiTranslationException(format(
+                        "group type %s not supported", group.type()));
+        }
     }
 
     private static Set<PiPreReplica> getReplicas(
diff --git a/core/net/src/main/java/org/onosproject/net/pi/impl/PiTranslationServiceImpl.java b/core/net/src/main/java/org/onosproject/net/pi/impl/PiTranslationServiceImpl.java
index 510ad01..18746d3 100644
--- a/core/net/src/main/java/org/onosproject/net/pi/impl/PiTranslationServiceImpl.java
+++ b/core/net/src/main/java/org/onosproject/net/pi/impl/PiTranslationServiceImpl.java
@@ -25,7 +25,7 @@
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.runtime.PiActionProfileGroup;
 import org.onosproject.net.pi.runtime.PiMeterCellConfig;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiPreEntry;
 import org.onosproject.net.pi.runtime.PiTableEntry;
 import org.onosproject.net.pi.service.PiFlowRuleTranslationStore;
 import org.onosproject.net.pi.service.PiFlowRuleTranslator;
@@ -33,8 +33,8 @@
 import org.onosproject.net.pi.service.PiGroupTranslator;
 import org.onosproject.net.pi.service.PiMeterTranslationStore;
 import org.onosproject.net.pi.service.PiMeterTranslator;
-import org.onosproject.net.pi.service.PiMulticastGroupTranslationStore;
-import org.onosproject.net.pi.service.PiMulticastGroupTranslator;
+import org.onosproject.net.pi.service.PiReplicationGroupTranslationStore;
+import org.onosproject.net.pi.service.PiReplicationGroupTranslator;
 import org.onosproject.net.pi.service.PiTranslationException;
 import org.onosproject.net.pi.service.PiTranslationService;
 import org.osgi.service.component.annotations.Activate;
@@ -67,21 +67,21 @@
     private PiGroupTranslationStore groupTranslationStore;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
-    private PiMulticastGroupTranslationStore mcGroupTranslationStore;
+    private PiReplicationGroupTranslationStore repGroupTranslationStore;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     private PiMeterTranslationStore meterTranslationStore;
 
     private PiFlowRuleTranslator flowRuleTranslator;
     private PiGroupTranslator groupTranslator;
-    private PiMulticastGroupTranslator mcGroupTranslator;
+    private PiReplicationGroupTranslator repGroupTranslator;
     private PiMeterTranslator meterTranslator;
 
     @Activate
     public void activate() {
         flowRuleTranslator = new InternalFlowRuleTranslator(flowRuleTranslationStore);
         groupTranslator = new InternalGroupTranslator(groupTranslationStore);
-        mcGroupTranslator = new InternalMulticastGroupTranslator(mcGroupTranslationStore);
+        repGroupTranslator = new InternalReplicationGroupTranslator(repGroupTranslationStore);
         meterTranslator = new InternalMeterTranslator(meterTranslationStore);
         log.info("Started");
     }
@@ -110,8 +110,8 @@
     }
 
     @Override
-    public PiMulticastGroupTranslator multicastGroupTranslator() {
-        return mcGroupTranslator;
+    public PiReplicationGroupTranslator replicationGroupTranslator() {
+        return repGroupTranslator;
     }
 
     private Device getDevice(DeviceId deviceId) throws PiTranslationException {
@@ -158,20 +158,20 @@
         }
     }
 
-    private final class InternalMulticastGroupTranslator
-            extends AbstractPiTranslatorImpl<Group, PiMulticastGroupEntry>
-            implements PiMulticastGroupTranslator {
+    private final class InternalReplicationGroupTranslator
+            extends AbstractPiTranslatorImpl<Group, PiPreEntry>
+            implements PiReplicationGroupTranslator {
 
-        private InternalMulticastGroupTranslator(PiMulticastGroupTranslationStore store) {
+        private InternalReplicationGroupTranslator(PiReplicationGroupTranslationStore store) {
             super(store);
         }
 
         @Override
-        public PiMulticastGroupEntry translate(Group original, PiPipeconf pipeconf)
+        public PiPreEntry translate(Group original, PiPipeconf pipeconf)
                 throws PiTranslationException {
             checkNotNull(original);
             checkNotNull(pipeconf);
-            return PiMulticastGroupTranslatorImpl.translate(
+            return PiReplicationGroupTranslatorImpl.translate(
                     original, pipeconf, getDevice(original.deviceId()));
         }
     }
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/PiMulticastGroupTranslatorImplTest.java b/core/net/src/test/java/org/onosproject/net/pi/impl/PiReplicationGroupTranslatorImplTest.java
similarity index 70%
rename from core/net/src/test/java/org/onosproject/net/pi/impl/PiMulticastGroupTranslatorImplTest.java
rename to core/net/src/test/java/org/onosproject/net/pi/impl/PiReplicationGroupTranslatorImplTest.java
index 9fb7076..7b5e213 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/PiMulticastGroupTranslatorImplTest.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/PiReplicationGroupTranslatorImplTest.java
@@ -30,35 +30,42 @@
 import org.onosproject.net.group.DefaultGroup;
 import org.onosproject.net.group.DefaultGroupBucket;
 import org.onosproject.net.group.DefaultGroupDescription;
+import org.onosproject.net.group.DefaultGroupKey;
 import org.onosproject.net.group.Group;
 import org.onosproject.net.group.GroupBucket;
 import org.onosproject.net.group.GroupBuckets;
 import org.onosproject.net.group.GroupDescription;
-import org.onosproject.net.pi.runtime.PiGroupKey;
+import org.onosproject.net.group.GroupKey;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntry;
 import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiPreEntry;
 import org.onosproject.net.pi.runtime.PiPreReplica;
 
 import java.util.List;
 import java.util.Set;
 
 import static org.onosproject.net.group.GroupDescription.Type.ALL;
-import static org.onosproject.pipelines.basic.BasicConstants.INGRESS_WCMP_CONTROL_WCMP_SELECTOR;
-import static org.onosproject.pipelines.basic.BasicConstants.INGRESS_WCMP_CONTROL_WCMP_TABLE;
+import static org.onosproject.net.group.GroupDescription.Type.CLONE;
 
 /**
- * Test for {@link PiMulticastGroupTranslatorImpl}.
+ * Test for {@link PiReplicationGroupTranslatorImpl}.
  */
-public class PiMulticastGroupTranslatorImplTest {
+public class PiReplicationGroupTranslatorImplTest {
     private static final DeviceId DEVICE_ID = DeviceId.deviceId("device:dummy:1");
     private static final ApplicationId APP_ID = TestApplicationId.create("dummy");
-    private static final GroupId GROUP_ID = GroupId.valueOf(1);
-    private static final PiGroupKey GROUP_KEY = new PiGroupKey(
-            INGRESS_WCMP_CONTROL_WCMP_TABLE, INGRESS_WCMP_CONTROL_WCMP_SELECTOR, GROUP_ID.id());
+    private static final int ENTRY_ID = 99;
+    private static final GroupId GROUP_ID = GroupId.valueOf(ENTRY_ID);
+    private static final GroupKey GROUP_KEY = new DefaultGroupKey(
+            String.valueOf(GROUP_ID.id()).getBytes());
 
     private static final List<GroupBucket> BUCKET_LIST = ImmutableList.of(
             allOutputBucket(1),
             allOutputBucket(2),
             allOutputBucket(3));
+    private static final List<GroupBucket> CLONE_BUCKET_LIST = ImmutableList.of(
+            cloneOutputBucket(1),
+            cloneOutputBucket(2),
+            cloneOutputBucket(3));
     private static final List<GroupBucket> BUCKET_LIST_2 = ImmutableList.of(
             allOutputBucket(1),
             allOutputBucket(2),
@@ -82,6 +89,11 @@
                     .withGroupId(GROUP_ID.id())
                     .addReplicas(REPLICAS)
                     .build();
+    private static final PiCloneSessionEntry PI_CLONE_SESSION_ENTRY =
+            PiCloneSessionEntry.builder()
+                    .withSessionId(ENTRY_ID)
+                    .addReplicas(REPLICAS)
+                    .build();
     private static final PiMulticastGroupEntry PI_MULTICAST_GROUP_2 =
             PiMulticastGroupEntry.builder()
                     .withGroupId(GROUP_ID.id())
@@ -89,12 +101,17 @@
                     .build();
 
     private static final GroupBuckets BUCKETS = new GroupBuckets(BUCKET_LIST);
+    private static final GroupBuckets CLONE_BUCKETS = new GroupBuckets(CLONE_BUCKET_LIST);
     private static final GroupBuckets BUCKETS_2 = new GroupBuckets(BUCKET_LIST_2);
 
     private static final GroupDescription ALL_GROUP_DESC = new DefaultGroupDescription(
             DEVICE_ID, ALL, BUCKETS, GROUP_KEY, GROUP_ID.id(), APP_ID);
     private static final Group ALL_GROUP = new DefaultGroup(GROUP_ID, ALL_GROUP_DESC);
 
+    private static final GroupDescription CLONE_GROUP_DESC = new DefaultGroupDescription(
+            DEVICE_ID, CLONE, CLONE_BUCKETS, GROUP_KEY, GROUP_ID.id(), APP_ID);
+    private static final Group CLONE_GROUP = new DefaultGroup(GROUP_ID, CLONE_GROUP_DESC);
+
     private static final GroupDescription ALL_GROUP_DESC_2 = new DefaultGroupDescription(
             DEVICE_ID, ALL, BUCKETS_2, GROUP_KEY, GROUP_ID.id(), APP_ID);
     private static final Group ALL_GROUP_2 = new DefaultGroup(GROUP_ID, ALL_GROUP_DESC_2);
@@ -107,17 +124,27 @@
         return DefaultGroupBucket.createAllGroupBucket(treatment);
     }
 
+    private static GroupBucket cloneOutputBucket(int portNum) {
+        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+                .setOutput(PortNumber.portNumber(portNum))
+                .build();
+        return DefaultGroupBucket.createCloneGroupBucket(treatment);
+    }
+
     @Test
     public void testTranslatePreGroups() throws Exception {
 
-        PiMulticastGroupEntry multicastGroup = PiMulticastGroupTranslatorImpl
+        PiPreEntry multicastGroup = PiReplicationGroupTranslatorImpl
                 .translate(ALL_GROUP, null, null);
-        PiMulticastGroupEntry multicastGroup2 = PiMulticastGroupTranslatorImpl
+        PiPreEntry multicastGroup2 = PiReplicationGroupTranslatorImpl
                 .translate(ALL_GROUP_2, null, null);
+        PiPreEntry cloneSessionEntry = PiReplicationGroupTranslatorImpl
+                .translate(CLONE_GROUP, null, null);
 
         new EqualsTester()
                 .addEqualityGroup(multicastGroup, PI_MULTICAST_GROUP)
                 .addEqualityGroup(multicastGroup2, PI_MULTICAST_GROUP_2)
+                .addEqualityGroup(cloneSessionEntry, PI_CLONE_SESSION_ENTRY)
                 .testEquals();
     }
 }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/pi/impl/DistributedPiMulticastGroupTranslationStore.java b/core/store/dist/src/main/java/org/onosproject/store/pi/impl/DistributedPiReplicationGroupTranslationStore.java
similarity index 60%
rename from core/store/dist/src/main/java/org/onosproject/store/pi/impl/DistributedPiMulticastGroupTranslationStore.java
rename to core/store/dist/src/main/java/org/onosproject/store/pi/impl/DistributedPiReplicationGroupTranslationStore.java
index dfa6652..82d1f0a 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/pi/impl/DistributedPiMulticastGroupTranslationStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/pi/impl/DistributedPiReplicationGroupTranslationStore.java
@@ -16,20 +16,21 @@
 
 package org.onosproject.store.pi.impl;
 
-import org.osgi.service.component.annotations.Component;
 import org.onosproject.net.group.Group;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
-import org.onosproject.net.pi.service.PiMulticastGroupTranslationStore;
+import org.onosproject.net.pi.runtime.PiPreEntry;
+import org.onosproject.net.pi.service.PiReplicationGroupTranslationStore;
+import org.osgi.service.component.annotations.Component;
 
 /**
- * Distributed implementation of a PI translation store for multicast groups.
+ * Distributed implementation of a PI translation store for groups that require
+ * packet replication.
  */
-@Component(immediate = true, service = PiMulticastGroupTranslationStore.class)
-public class DistributedPiMulticastGroupTranslationStore
-        extends AbstractDistributedPiTranslationStore<Group, PiMulticastGroupEntry>
-        implements PiMulticastGroupTranslationStore {
+@Component(immediate = true, service = PiReplicationGroupTranslationStore.class)
+public class DistributedPiReplicationGroupTranslationStore
+        extends AbstractDistributedPiTranslationStore<Group, PiPreEntry>
+        implements PiReplicationGroupTranslationStore {
 
-    private static final String MAP_SIMPLE_NAME = "mc-group";
+    private static final String MAP_SIMPLE_NAME = "replication-group";
 
     @Override
     protected String mapSimpleName() {
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
index e2b826d..db5e28d 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
@@ -231,8 +231,11 @@
 import org.onosproject.net.pi.runtime.PiActionProfileMember;
 import org.onosproject.net.pi.runtime.PiActionProfileMemberHandle;
 import org.onosproject.net.pi.runtime.PiActionProfileMemberId;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntry;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntryHandle;
 import org.onosproject.net.pi.runtime.PiCounterCell;
 import org.onosproject.net.pi.runtime.PiCounterCellData;
+import org.onosproject.net.pi.runtime.PiCounterCellHandle;
 import org.onosproject.net.pi.runtime.PiCounterCellId;
 import org.onosproject.net.pi.runtime.PiEntity;
 import org.onosproject.net.pi.runtime.PiEntityType;
@@ -242,10 +245,21 @@
 import org.onosproject.net.pi.runtime.PiHandle;
 import org.onosproject.net.pi.runtime.PiLpmFieldMatch;
 import org.onosproject.net.pi.runtime.PiMatchKey;
+import org.onosproject.net.pi.runtime.PiMeterBand;
+import org.onosproject.net.pi.runtime.PiMeterCellConfig;
+import org.onosproject.net.pi.runtime.PiMeterCellHandle;
 import org.onosproject.net.pi.runtime.PiMeterCellId;
+import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
 import org.onosproject.net.pi.runtime.PiPacketMetadata;
 import org.onosproject.net.pi.runtime.PiPacketOperation;
+import org.onosproject.net.pi.runtime.PiPreEntry;
+import org.onosproject.net.pi.runtime.PiPreEntryHandle;
+import org.onosproject.net.pi.runtime.PiPreEntryType;
+import org.onosproject.net.pi.runtime.PiPreReplica;
 import org.onosproject.net.pi.runtime.PiRangeFieldMatch;
+import org.onosproject.net.pi.runtime.PiRegisterCell;
+import org.onosproject.net.pi.runtime.PiRegisterCellId;
 import org.onosproject.net.pi.runtime.PiTableAction;
 import org.onosproject.net.pi.runtime.PiTableEntry;
 import org.onosproject.net.pi.runtime.PiTableEntryHandle;
@@ -687,16 +701,18 @@
                     PiTableType.class,
                     // PI Runtime
                     PiAction.class,
+                    PiActionParam.class,
                     PiActionProfileGroup.class,
                     PiActionProfileGroupHandle.class,
                     PiActionProfileGroupId.class,
                     PiActionProfileMember.class,
                     PiActionProfileMemberHandle.class,
                     PiActionProfileMemberId.class,
-                    PiActionParam.class,
-                    PiPacketMetadata.class,
+                    PiCloneSessionEntry.class,
+                    PiCloneSessionEntryHandle.class,
                     PiCounterCell.class,
                     PiCounterCellData.class,
+                    PiCounterCellHandle.class,
                     PiCounterCellId.class,
                     PiEntity.class,
                     PiEntityType.class,
@@ -706,13 +722,26 @@
                     PiHandle.class,
                     PiLpmFieldMatch.class,
                     PiMatchKey.class,
+                    PiMeterBand.class,
+                    PiMeterCellConfig.class,
+                    PiMeterCellHandle.class,
+                    PiMeterCellId.class,
+                    PiMulticastGroupEntry.class,
+                    PiMulticastGroupEntryHandle.class,
+                    PiPacketMetadata.class,
                     PiPacketOperation.class,
+                    PiPreEntry.class,
+                    PiPreEntryHandle.class,
+                    PiPreEntryType.class,
+                    PiPreReplica.class,
                     PiRangeFieldMatch.class,
+                    PiRegisterCell.class,
+                    PiRegisterCellId.class,
                     PiTableAction.class,
                     PiTableEntry.class,
+                    PiTableEntryHandle.class,
                     PiTernaryFieldMatch.class,
                     // PI service
-                    PiTableEntryHandle.class,
                     PiTranslatedEntity.class,
                     PiTranslatable.class,
                     // Other
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java
index 84678dc..f38b504 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java
@@ -21,7 +21,6 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 import org.onosproject.net.group.Group;
-import org.onosproject.net.group.GroupDescription;
 import org.onosproject.net.group.GroupOperation;
 import org.onosproject.net.group.GroupOperations;
 import org.onosproject.net.group.GroupProgrammable;
@@ -37,7 +36,7 @@
 /**
  * Implementation of GroupProgrammable for P4Runtime devices that uses two
  * different implementation of the same behavior to handle both action profile
- * groups and multicast groups.
+ * groups and PRE entries.
  */
 public class P4RuntimeGroupProgrammable
         extends AbstractHandlerBehaviour implements GroupProgrammable {
@@ -49,28 +48,36 @@
         checkArgument(deviceId.equals(data().deviceId()),
                       "passed deviceId must be the same assigned to this behavior");
         final List<GroupOperation> actionGroups = Lists.newArrayList();
-        final List<GroupOperation> multicastGroups = Lists.newArrayList();
+        final List<GroupOperation> preGroups = Lists.newArrayList();
         groupOps.operations().forEach(op -> {
-            if (op.groupType().equals(GroupDescription.Type.ALL)) {
-                multicastGroups.add(op);
-            } else {
-                actionGroups.add(op);
+            switch (op.groupType()) {
+                case SELECT:
+                    actionGroups.add(op);
+                    break;
+                case ALL:
+                case CLONE:
+                    preGroups.add(op);
+                    break;
+                case FAILOVER:
+                case INDIRECT:
+                default:
+                    log.warn("{} group type not supported [{}]", op.groupType(), op);
             }
         });
         if (!actionGroups.isEmpty()) {
             actionProgrammable().performGroupOperation(
                     deviceId, new GroupOperations(actionGroups));
         }
-        if (!multicastGroups.isEmpty()) {
-            multicastProgrammable().performGroupOperation(
-                    deviceId, new GroupOperations(multicastGroups));
+        if (!preGroups.isEmpty()) {
+            replicationProgrammable().performGroupOperation(
+                    deviceId, new GroupOperations(preGroups));
         }
     }
 
     private Collection<Group> doGetGroups() {
         return new ImmutableList.Builder<Group>()
                 .addAll(actionProgrammable().getGroups())
-                .addAll(multicastProgrammable().getGroups())
+                .addAll(replicationProgrammable().getGroups())
                 .build();
     }
 
@@ -81,8 +88,8 @@
         return prog;
     }
 
-    private P4RuntimeMulticastGroupProgrammable multicastProgrammable() {
-        P4RuntimeMulticastGroupProgrammable prog = new P4RuntimeMulticastGroupProgrammable();
+    private P4RuntimeReplicationGroupProgrammable replicationProgrammable() {
+        P4RuntimeReplicationGroupProgrammable prog = new P4RuntimeReplicationGroupProgrammable();
         prog.setData(data());
         prog.setHandler(handler());
         return prog;
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeMulticastGroupProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeMulticastGroupProgrammable.java
deleted file mode 100644
index 212ada2..0000000
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeMulticastGroupProgrammable.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright 2018-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.drivers.p4runtime;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.Striped;
-import org.onosproject.drivers.p4runtime.mirror.P4RuntimeMulticastGroupMirror;
-import org.onosproject.drivers.p4runtime.mirror.TimedEntry;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.group.DefaultGroup;
-import org.onosproject.net.group.Group;
-import org.onosproject.net.group.GroupDescription;
-import org.onosproject.net.group.GroupOperation;
-import org.onosproject.net.group.GroupOperations;
-import org.onosproject.net.group.GroupProgrammable;
-import org.onosproject.net.group.GroupStore;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
-import org.onosproject.net.pi.service.PiMulticastGroupTranslator;
-import org.onosproject.net.pi.service.PiTranslatedEntity;
-import org.onosproject.net.pi.service.PiTranslationException;
-import org.onosproject.p4runtime.api.P4RuntimeClient;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.locks.Lock;
-import java.util.stream.Collectors;
-
-import static org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType.DELETE;
-import static org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType.INSERT;
-import static org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType.MODIFY;
-
-/**
- * Implementation of GroupProgrammable to handle multicast groups in P4Runtime.
- */
-public class P4RuntimeMulticastGroupProgrammable
-        extends AbstractP4RuntimeHandlerBehaviour implements GroupProgrammable {
-
-    // TODO: implement reading groups from device and mirror sync.
-
-    // Needed to synchronize operations over the same group.
-    private static final Striped<Lock> STRIPED_LOCKS = Striped.lock(30);
-
-    private GroupStore groupStore;
-    private P4RuntimeMulticastGroupMirror mcGroupMirror;
-    private PiMulticastGroupTranslator mcGroupTranslator;
-
-    @Override
-    protected boolean setupBehaviour(String opName) {
-        if (!super.setupBehaviour(opName)) {
-            return false;
-        }
-        mcGroupMirror = this.handler().get(P4RuntimeMulticastGroupMirror.class);
-        groupStore = handler().get(GroupStore.class);
-        mcGroupTranslator = translationService.multicastGroupTranslator();
-        return true;
-    }
-
-    @Override
-    public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
-        if (!setupBehaviour("performGroupOperation()")) {
-            return;
-        }
-        groupOps.operations().stream()
-                .filter(op -> op.groupType().equals(GroupDescription.Type.ALL))
-                .forEach(op -> {
-                    final Group group = groupStore.getGroup(deviceId, op.groupId());
-                    if (group == null) {
-                        log.warn("Unable to find group {} in store, aborting {} operation [{}]",
-                                 op.groupId(), op.opType(), op);
-                        return;
-                    }
-                    processMcGroupOp(group, op.opType());
-                });
-    }
-
-    @Override
-    public Collection<Group> getGroups() {
-        if (!setupBehaviour("getGroups()")) {
-            return Collections.emptyList();
-        }
-        return ImmutableList.copyOf(getMcGroups());
-    }
-
-    private Collection<Group> getMcGroups() {
-        // TODO: missing support for reading multicast groups in PI/Stratum.
-        return getMcGroupsFromMirror();
-    }
-
-    private Collection<Group> getMcGroupsFromMirror() {
-        return mcGroupMirror.getAll(deviceId).stream()
-                .map(TimedEntry::entry)
-                .map(this::forgeMcGroupEntry)
-                .filter(Objects::nonNull)
-                .collect(Collectors.toList());
-    }
-
-    private void processMcGroupOp(Group pdGroup, GroupOperation.Type opType) {
-        final PiMulticastGroupEntry mcGroup;
-        try {
-            mcGroup = mcGroupTranslator.translate(pdGroup, pipeconf);
-        } catch (PiTranslationException e) {
-            log.warn("Unable to translate multicast group, aborting {} operation: {} [{}]",
-                     opType, e.getMessage(), pdGroup);
-            return;
-        }
-        final PiMulticastGroupEntryHandle handle = PiMulticastGroupEntryHandle.of(
-                deviceId, mcGroup);
-        final PiMulticastGroupEntry groupOnDevice = mcGroupMirror.get(handle) == null
-                ? null
-                : mcGroupMirror.get(handle).entry();
-        final Lock lock = STRIPED_LOCKS.get(handle);
-        lock.lock();
-        try {
-            processMcGroup(handle, mcGroup,
-                           groupOnDevice, pdGroup, opType);
-        } finally {
-            lock.unlock();
-        }
-    }
-
-    private void processMcGroup(PiMulticastGroupEntryHandle handle,
-                                PiMulticastGroupEntry groupToApply,
-                                PiMulticastGroupEntry groupOnDevice,
-                                Group pdGroup, GroupOperation.Type opType) {
-        switch (opType) {
-            case ADD:
-                robustMcGroupAdd(handle, groupToApply, pdGroup);
-                return;
-            case MODIFY:
-                // Since reading multicast groups is not supported yet on
-                // PI/Stratum, we cannot trust groupOnDevice as we don't have a
-                // mechanism to enforce consistency of the mirror with the
-                // device state.
-                // if (driverBoolProperty(CHECK_MIRROR_BEFORE_UPDATE,
-                //                        DEFAULT_CHECK_MIRROR_BEFORE_UPDATE)
-                //         && p4OpType == MODIFY
-                //         && groupOnDevice != null
-                //         && groupOnDevice.equals(groupToApply)) {
-                //     // Ignore.
-                //     return;
-                // }
-                robustMcGroupModify(handle, groupToApply, pdGroup);
-                return;
-            case DELETE:
-                mcGroupApply(handle, groupToApply, pdGroup, DELETE);
-                return;
-            default:
-                log.error("Unknown group operation type {}, " +
-                                  "cannot process multicast group", opType);
-        }
-    }
-
-    private boolean writeMcGroupOnDevice(
-            PiMulticastGroupEntry group, P4RuntimeClient.UpdateType opType) {
-        return client.write(p4DeviceId, pipeconf)
-                .entity(group, opType).submitSync().isSuccess();
-    }
-
-    private boolean mcGroupApply(PiMulticastGroupEntryHandle handle,
-                                 PiMulticastGroupEntry piGroup,
-                                 Group pdGroup,
-                                 P4RuntimeClient.UpdateType opType) {
-        switch (opType) {
-            case DELETE:
-                if (writeMcGroupOnDevice(piGroup, DELETE)) {
-                    mcGroupMirror.remove(handle);
-                    mcGroupTranslator.forget(handle);
-                    return true;
-                } else {
-                    return false;
-                }
-            case INSERT:
-            case MODIFY:
-                if (writeMcGroupOnDevice(piGroup, opType)) {
-                    mcGroupMirror.put(handle, piGroup);
-                    mcGroupTranslator.learn(handle, new PiTranslatedEntity<>(
-                            pdGroup, piGroup, handle));
-                    return true;
-                } else {
-                    return false;
-                }
-            default:
-                log.warn("Unknown operation type {}, cannot apply group", opType);
-                return false;
-        }
-    }
-
-    private void robustMcGroupAdd(PiMulticastGroupEntryHandle handle,
-                                  PiMulticastGroupEntry piGroup,
-                                  Group pdGroup) {
-        if (mcGroupApply(handle, piGroup, pdGroup, INSERT)) {
-            return;
-        }
-        // Try to delete (perhaps it already exists) and re-add...
-        mcGroupApply(handle, piGroup, pdGroup, DELETE);
-        mcGroupApply(handle, piGroup, pdGroup, INSERT);
-    }
-
-    private void robustMcGroupModify(PiMulticastGroupEntryHandle handle,
-                                     PiMulticastGroupEntry piGroup,
-                                     Group pdGroup) {
-        if (mcGroupApply(handle, piGroup, pdGroup, MODIFY)) {
-            return;
-        }
-        // Not sure for which reason it cannot be modified, so try to delete and insert instead...
-        mcGroupApply(handle, piGroup, pdGroup, DELETE);
-        mcGroupApply(handle, piGroup, pdGroup, INSERT);
-    }
-
-    private Group forgeMcGroupEntry(PiMulticastGroupEntry mcGroup) {
-        final PiMulticastGroupEntryHandle handle = PiMulticastGroupEntryHandle.of(
-                deviceId, mcGroup);
-        final Optional<PiTranslatedEntity<Group, PiMulticastGroupEntry>>
-                translatedEntity = mcGroupTranslator.lookup(handle);
-        final TimedEntry<PiMulticastGroupEntry> timedEntry = mcGroupMirror.get(handle);
-        // Is entry consistent with our state?
-        if (!translatedEntity.isPresent()) {
-            log.warn("Multicast group handle not found in translation store: {}", handle);
-            return null;
-        }
-        if (timedEntry == null) {
-            log.warn("Multicast group handle not found in device mirror: {}", handle);
-            return null;
-        }
-        return addedGroup(translatedEntity.get().original(), timedEntry.lifeSec());
-    }
-
-    private Group addedGroup(Group original, long life) {
-        final DefaultGroup forgedGroup = new DefaultGroup(original.id(), original);
-        forgedGroup.setState(Group.GroupState.ADDED);
-        forgedGroup.setLife(life);
-        return forgedGroup;
-    }
-
-}
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeReplicationGroupProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeReplicationGroupProgrammable.java
new file mode 100644
index 0000000..483bd0e
--- /dev/null
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeReplicationGroupProgrammable.java
@@ -0,0 +1,245 @@
+/*
+ * Copyright 2018-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.drivers.p4runtime;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.Striped;
+import org.onosproject.drivers.p4runtime.mirror.P4RuntimePreEntryMirror;
+import org.onosproject.drivers.p4runtime.mirror.TimedEntry;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.group.DefaultGroup;
+import org.onosproject.net.group.Group;
+import org.onosproject.net.group.GroupDescription;
+import org.onosproject.net.group.GroupOperation;
+import org.onosproject.net.group.GroupOperations;
+import org.onosproject.net.group.GroupProgrammable;
+import org.onosproject.net.group.GroupStore;
+import org.onosproject.net.pi.runtime.PiPreEntry;
+import org.onosproject.net.pi.runtime.PiPreEntryHandle;
+import org.onosproject.net.pi.service.PiReplicationGroupTranslator;
+import org.onosproject.net.pi.service.PiTranslatedEntity;
+import org.onosproject.net.pi.service.PiTranslationException;
+import org.onosproject.p4runtime.api.P4RuntimeClient;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.locks.Lock;
+import java.util.stream.Collectors;
+
+import static org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType.DELETE;
+import static org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType.INSERT;
+import static org.onosproject.p4runtime.api.P4RuntimeWriteClient.UpdateType.MODIFY;
+
+/**
+ * Implementation of GroupProgrammable to handle PRE entries in P4Runtime.
+ */
+public class P4RuntimeReplicationGroupProgrammable
+        extends AbstractP4RuntimeHandlerBehaviour implements GroupProgrammable {
+
+    // TODO: implement reading groups from device and mirror sync.
+
+    // Needed to synchronize operations over the same group.
+    private static final Striped<Lock> STRIPED_LOCKS = Striped.lock(30);
+
+    private GroupStore groupStore;
+    private P4RuntimePreEntryMirror mirror;
+    private PiReplicationGroupTranslator translator;
+
+    @Override
+    protected boolean setupBehaviour(String opName) {
+        if (!super.setupBehaviour(opName)) {
+            return false;
+        }
+        mirror = this.handler().get(P4RuntimePreEntryMirror.class);
+        groupStore = handler().get(GroupStore.class);
+        translator = translationService.replicationGroupTranslator();
+        return true;
+    }
+
+    @Override
+    public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
+        if (!setupBehaviour("performGroupOperation()")) {
+            return;
+        }
+        groupOps.operations().stream()
+                .filter(op -> op.groupType().equals(GroupDescription.Type.ALL))
+                .forEach(op -> {
+                    final Group group = groupStore.getGroup(deviceId, op.groupId());
+                    if (group == null) {
+                        log.warn("Unable to find group {} in store, aborting {} operation [{}]",
+                                 op.groupId(), op.opType(), op);
+                        return;
+                    }
+                    processGroupOp(group, op.opType());
+                });
+    }
+
+    @Override
+    public Collection<Group> getGroups() {
+        if (!setupBehaviour("getGroups()")) {
+            return Collections.emptyList();
+        }
+        // TODO: missing support for reading multicast groups in PI/Stratum.
+        return ImmutableList.copyOf(getGroupsFromMirror());
+    }
+
+    private Collection<Group> getGroupsFromMirror() {
+        return mirror.getAll(deviceId).stream()
+                .map(TimedEntry::entry)
+                .map(this::forgeGroupEntry)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+    }
+
+    private void processGroupOp(Group pdGroup, GroupOperation.Type opType) {
+        final PiPreEntry preEntry;
+        try {
+            preEntry = translator.translate(pdGroup, pipeconf);
+        } catch (PiTranslationException e) {
+            log.warn("Unable to translate replication group, aborting {} operation: {} [{}]",
+                     opType, e.getMessage(), pdGroup);
+            return;
+        }
+        final PiPreEntryHandle handle = (PiPreEntryHandle) preEntry.handle(deviceId);
+        final PiPreEntry entryOnDevice = mirror.get(handle) == null
+                ? null : mirror.get(handle).entry();
+        final Lock lock = STRIPED_LOCKS.get(handle);
+        lock.lock();
+        try {
+            processPreEntry(handle, preEntry,
+                            entryOnDevice, pdGroup, opType);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    private void processPreEntry(PiPreEntryHandle handle,
+                                 PiPreEntry entryToApply,
+                                 PiPreEntry entryOnDevice,
+                                 Group pdGroup, GroupOperation.Type opType) {
+        switch (opType) {
+            case ADD:
+                robustInsert(handle, entryToApply, pdGroup);
+                return;
+            case MODIFY:
+                // Since reading multicast groups is not supported yet on
+                // PI/Stratum, we cannot trust groupOnDevice as we don't have a
+                // mechanism to enforce consistency of the mirror with the
+                // device state.
+                // if (driverBoolProperty(CHECK_MIRROR_BEFORE_UPDATE,
+                //                        DEFAULT_CHECK_MIRROR_BEFORE_UPDATE)
+                //         && p4OpType == MODIFY
+                //         && groupOnDevice != null
+                //         && groupOnDevice.equals(groupToApply)) {
+                //     // Ignore.
+                //     return;
+                // }
+                robustModify(handle, entryToApply, pdGroup);
+                return;
+            case DELETE:
+                preEntryWrite(handle, entryToApply, pdGroup, DELETE);
+                return;
+            default:
+                log.error("Unknown group operation type {}, " +
+                                  "cannot process multicast group", opType);
+        }
+    }
+
+    private boolean writeEntryOnDevice(
+            PiPreEntry entry, P4RuntimeClient.UpdateType opType) {
+        return client.write(p4DeviceId, pipeconf)
+                .entity(entry, opType).submitSync().isSuccess();
+    }
+
+    private boolean preEntryWrite(PiPreEntryHandle handle,
+                                  PiPreEntry preEntry,
+                                  Group pdGroup,
+                                  P4RuntimeClient.UpdateType opType) {
+        switch (opType) {
+            case DELETE:
+                if (writeEntryOnDevice(preEntry, DELETE)) {
+                    mirror.remove(handle);
+                    translator.forget(handle);
+                    return true;
+                } else {
+                    return false;
+                }
+            case INSERT:
+            case MODIFY:
+                if (writeEntryOnDevice(preEntry, opType)) {
+                    mirror.put(handle, preEntry);
+                    translator.learn(handle, new PiTranslatedEntity<>(
+                            pdGroup, preEntry, handle));
+                    return true;
+                } else {
+                    return false;
+                }
+            default:
+                log.warn("Unknown operation type {}, cannot apply group", opType);
+                return false;
+        }
+    }
+
+    private void robustInsert(PiPreEntryHandle handle,
+                              PiPreEntry preEntry,
+                              Group pdGroup) {
+        if (preEntryWrite(handle, preEntry, pdGroup, INSERT)) {
+            return;
+        }
+        // Try to delete (perhaps it already exists) and re-add...
+        preEntryWrite(handle, preEntry, pdGroup, DELETE);
+        preEntryWrite(handle, preEntry, pdGroup, INSERT);
+    }
+
+    private void robustModify(PiPreEntryHandle handle,
+                              PiPreEntry preEntry,
+                              Group pdGroup) {
+        if (preEntryWrite(handle, preEntry, pdGroup, MODIFY)) {
+            return;
+        }
+        // Not sure for which reason it cannot be modified, so try to delete and insert instead...
+        preEntryWrite(handle, preEntry, pdGroup, DELETE);
+        preEntryWrite(handle, preEntry, pdGroup, INSERT);
+    }
+
+    private Group forgeGroupEntry(PiPreEntry preEntry) {
+        final PiPreEntryHandle handle = (PiPreEntryHandle) preEntry.handle(deviceId);
+        final Optional<PiTranslatedEntity<Group, PiPreEntry>>
+                translatedEntity = translator.lookup(handle);
+        final TimedEntry<PiPreEntry> timedEntry = mirror.get(handle);
+        // Is entry consistent with our state?
+        if (!translatedEntity.isPresent()) {
+            log.warn("PRE entry handle not found in translation store: {}", handle);
+            return null;
+        }
+        if (timedEntry == null) {
+            log.warn("PRE entry handle not found in device mirror: {}", handle);
+            return null;
+        }
+        return addedGroup(translatedEntity.get().original(), timedEntry.lifeSec());
+    }
+
+    private Group addedGroup(Group original, long life) {
+        final DefaultGroup forgedGroup = new DefaultGroup(original.id(), original);
+        forgedGroup.setState(Group.GroupState.ADDED);
+        forgedGroup.setLife(life);
+        return forgedGroup;
+    }
+
+}
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/DistributedP4RuntimeMulticastGroupMirror.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/DistributedP4RuntimeMulticastGroupMirror.java
deleted file mode 100644
index 5ccaec5..0000000
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/DistributedP4RuntimeMulticastGroupMirror.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2018-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.drivers.p4runtime.mirror;
-
-import org.onosproject.net.pi.runtime.PiEntityType;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
-import org.osgi.service.component.annotations.Component;
-
-/**
- * Distributed implementation of a P4Runtime multicast group mirror.
- */
-@Component(immediate = true, service = P4RuntimeMulticastGroupMirror.class)
-public final class DistributedP4RuntimeMulticastGroupMirror
-        extends AbstractDistributedP4RuntimeMirror
-                        <PiMulticastGroupEntryHandle, PiMulticastGroupEntry>
-        implements P4RuntimeMulticastGroupMirror {
-
-    public DistributedP4RuntimeMulticastGroupMirror() {
-        super(PiEntityType.PRE_MULTICAST_GROUP_ENTRY);
-    }
-}
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/DistributedP4RuntimePreEntryMirror.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/DistributedP4RuntimePreEntryMirror.java
new file mode 100644
index 0000000..4876aaa
--- /dev/null
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/DistributedP4RuntimePreEntryMirror.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2018-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.drivers.p4runtime.mirror;
+
+import org.onosproject.net.pi.runtime.PiEntityType;
+import org.onosproject.net.pi.runtime.PiPreEntry;
+import org.onosproject.net.pi.runtime.PiPreEntryHandle;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Distributed implementation of a P4Runtime PRE entry mirror.
+ */
+@Component(immediate = true, service = P4RuntimePreEntryMirror.class)
+public final class DistributedP4RuntimePreEntryMirror
+        extends AbstractDistributedP4RuntimeMirror<PiPreEntryHandle, PiPreEntry>
+        implements P4RuntimePreEntryMirror {
+
+    public DistributedP4RuntimePreEntryMirror() {
+        super(PiEntityType.PRE_ENTRY);
+    }
+}
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/P4RuntimeMulticastGroupMirror.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/P4RuntimePreEntryMirror.java
similarity index 67%
rename from drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/P4RuntimeMulticastGroupMirror.java
rename to drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/P4RuntimePreEntryMirror.java
index d901f29..c6a5fcf 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/P4RuntimeMulticastGroupMirror.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/P4RuntimePreEntryMirror.java
@@ -16,12 +16,12 @@
 
 package org.onosproject.drivers.p4runtime.mirror;
 
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
+import org.onosproject.net.pi.runtime.PiPreEntry;
+import org.onosproject.net.pi.runtime.PiPreEntryHandle;
 
 /**
- * Mirror of multicast groups installed on a P4Runtime device.
+ * Mirror of PRE entries installed on a P4Runtime device.
  */
-public interface P4RuntimeMulticastGroupMirror
-        extends P4RuntimeMirror<PiMulticastGroupEntryHandle, PiMulticastGroupEntry> {
+public interface P4RuntimePreEntryMirror
+        extends P4RuntimeMirror<PiPreEntryHandle, PiPreEntry> {
 }
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/CloneSessionEntryCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/CloneSessionEntryCodec.java
new file mode 100644
index 0000000..337d76a
--- /dev/null
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/CloneSessionEntryCodec.java
@@ -0,0 +1,77 @@
+/*
+ * 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 org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntry;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntryHandle;
+import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser;
+import p4.v1.P4RuntimeOuterClass;
+
+import static org.onosproject.p4runtime.ctl.codec.Codecs.CODECS;
+
+/**
+ * Codec for P4Runtime CloneSessionEntry.
+ */
+public final class CloneSessionEntryCodec
+        extends AbstractEntityCodec<PiCloneSessionEntry, PiCloneSessionEntryHandle,
+        P4RuntimeOuterClass.CloneSessionEntry, Object> {
+
+    @Override
+    protected P4RuntimeOuterClass.CloneSessionEntry encode(
+            PiCloneSessionEntry piEntity, Object ignored,
+            PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException {
+        return P4RuntimeOuterClass.CloneSessionEntry.newBuilder()
+                .setSessionId(piEntity.sessionId())
+                .addAllReplicas(
+                        CODECS.preReplica().encodeAll(
+                                piEntity.replicas(), null, pipeconf))
+                .setClassOfService(piEntity.classOfService())
+                .setPacketLengthBytes(piEntity.maxPacketLengthBytes())
+                .build();
+    }
+
+    @Override
+    protected P4RuntimeOuterClass.CloneSessionEntry encodeKey(
+            PiCloneSessionEntryHandle handle, Object metadata,
+            PiPipeconf pipeconf, P4InfoBrowser browser) {
+        return P4RuntimeOuterClass.CloneSessionEntry.newBuilder()
+                .setSessionId(handle.sessionId()).build();
+    }
+
+    @Override
+    protected P4RuntimeOuterClass.CloneSessionEntry encodeKey(
+            PiCloneSessionEntry piEntity, Object metadata,
+            PiPipeconf pipeconf, P4InfoBrowser browser) {
+        return P4RuntimeOuterClass.CloneSessionEntry.newBuilder()
+                .setSessionId(piEntity.sessionId()).build();
+    }
+
+    @Override
+    protected PiCloneSessionEntry decode(
+            P4RuntimeOuterClass.CloneSessionEntry message, Object ignored,
+            PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException {
+        return PiCloneSessionEntry.builder()
+                .withSessionId(message.getSessionId())
+                .addReplicas(
+                        CODECS.preReplica().decodeAll(
+                                message.getReplicasList(), null, pipeconf))
+                .withClassOfService(message.getClassOfService())
+                .withMaxPacketLengthBytes(message.getPacketLengthBytes())
+                .build();
+    }
+}
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/Codecs.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/Codecs.java
index 771f5da..30e8d9d 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/Codecs.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/Codecs.java
@@ -34,6 +34,8 @@
     private final HandleCodec handle;
     private final MeterEntryCodec meterEntry;
     private final MulticastGroupEntryCodec multicastGroupEntry;
+    private final CloneSessionEntryCodec cloneSessionEntry;
+    private final PreReplicaCodec preReplica;
     private final PacketInCodec packetIn;
     private final PacketMetadataCodec packetMetadata;
     private final PacketOutCodec packetOut;
@@ -51,6 +53,8 @@
         this.handle = new HandleCodec();
         this.meterEntry = new MeterEntryCodec();
         this.multicastGroupEntry = new MulticastGroupEntryCodec();
+        this.cloneSessionEntry = new CloneSessionEntryCodec();
+        this.preReplica = new PreReplicaCodec();
         this.packetIn = new PacketInCodec();
         this.packetMetadata = new PacketMetadataCodec();
         this.packetOut = new PacketOutCodec();
@@ -101,6 +105,14 @@
         return multicastGroupEntry;
     }
 
+    CloneSessionEntryCodec cloneSessionEntry() {
+        return cloneSessionEntry;
+    }
+
+    PreReplicaCodec preReplica() {
+        return preReplica;
+    }
+
     DirectMeterEntryCodec directMeterEntry() {
         return directMeterEntry;
     }
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/EntityCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/EntityCodec.java
index dc10419..e063faa 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/EntityCodec.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/EntityCodec.java
@@ -19,10 +19,12 @@
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.runtime.PiActionProfileGroup;
 import org.onosproject.net.pi.runtime.PiActionProfileMember;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntry;
 import org.onosproject.net.pi.runtime.PiCounterCell;
 import org.onosproject.net.pi.runtime.PiEntity;
 import org.onosproject.net.pi.runtime.PiMeterCellConfig;
 import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
+import org.onosproject.net.pi.runtime.PiPreEntry;
 import org.onosproject.net.pi.runtime.PiTableEntry;
 import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser;
 import p4.v1.P4RuntimeOuterClass;
@@ -56,13 +58,29 @@
                         CODECS.actionProfileMember().encode(
                                 (PiActionProfileMember) piEntity, null, pipeconf))
                         .build();
-            case PRE_MULTICAST_GROUP_ENTRY:
-                return p4Entity.setPacketReplicationEngineEntry(
-                        P4RuntimeOuterClass.PacketReplicationEngineEntry.newBuilder()
-                                .setMulticastGroupEntry(CODECS.multicastGroupEntry().encode(
-                                        (PiMulticastGroupEntry) piEntity, null, pipeconf))
-                                .build())
-                        .build();
+            case PRE_ENTRY:
+                final PiPreEntry preEntry = (PiPreEntry) piEntity;
+                switch (preEntry.preEntryType()) {
+                    case MULTICAST_GROUP:
+                        return p4Entity.setPacketReplicationEngineEntry(
+                                P4RuntimeOuterClass.PacketReplicationEngineEntry.newBuilder()
+                                        .setMulticastGroupEntry(CODECS.multicastGroupEntry().encode(
+                                                (PiMulticastGroupEntry) piEntity, null, pipeconf))
+                                        .build())
+                                .build();
+                    case CLONE_SESSION:
+                        return p4Entity.setPacketReplicationEngineEntry(
+                                P4RuntimeOuterClass.PacketReplicationEngineEntry.newBuilder()
+                                        .setCloneSessionEntry(CODECS.cloneSessionEntry().encode(
+                                                (PiCloneSessionEntry) piEntity, null, pipeconf))
+                                        .build())
+                                .build();
+                    default:
+                        throw new CodecException(format(
+                                "Encoding of %s of type %s is not supported",
+                                piEntity.piEntityType(),
+                                preEntry.preEntryType()));
+                }
             case METER_CELL_CONFIG:
                 final PiMeterCellConfig meterCellConfig = (PiMeterCellConfig) piEntity;
                 switch (meterCellConfig.cellId().meterType()) {
@@ -102,7 +120,6 @@
                                 counterCell.cellId().counterType()));
                 }
             case REGISTER_CELL:
-            case PRE_CLONE_SESSION_ENTRY:
             default:
                 throw new CodecException(format(
                         "Encoding of %s not supported",
@@ -113,7 +130,7 @@
     @Override
     protected PiEntity decode(
             P4RuntimeOuterClass.Entity message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser)
-            throws CodecException, P4InfoBrowser.NotFoundException {
+            throws CodecException {
         switch (message.getEntityCase()) {
             case TABLE_ENTRY:
                 return CODECS.tableEntry().decode(
@@ -143,6 +160,9 @@
                                 message.getPacketReplicationEngineEntry()
                                         .getMulticastGroupEntry(), null, pipeconf);
                     case CLONE_SESSION_ENTRY:
+                        return CODECS.cloneSessionEntry().decode(
+                                message.getPacketReplicationEngineEntry()
+                                        .getCloneSessionEntry(), null, pipeconf);
                     case TYPE_NOT_SET:
                     default:
                         throw new CodecException(format(
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/HandleCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/HandleCodec.java
index dc617cf..7a9c727 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/HandleCodec.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/HandleCodec.java
@@ -19,10 +19,12 @@
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.runtime.PiActionProfileGroupHandle;
 import org.onosproject.net.pi.runtime.PiActionProfileMemberHandle;
+import org.onosproject.net.pi.runtime.PiCloneSessionEntryHandle;
 import org.onosproject.net.pi.runtime.PiCounterCellHandle;
 import org.onosproject.net.pi.runtime.PiHandle;
 import org.onosproject.net.pi.runtime.PiMeterCellHandle;
 import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
+import org.onosproject.net.pi.runtime.PiPreEntryHandle;
 import org.onosproject.net.pi.runtime.PiTableEntryHandle;
 import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser;
 import p4.v1.P4RuntimeOuterClass;
@@ -55,13 +57,29 @@
                         CODECS.actionProfileMember().encodeKey(
                                 (PiActionProfileMemberHandle) piHandle, null, pipeconf))
                         .build();
-            case PRE_MULTICAST_GROUP_ENTRY:
-                return p4Entity.setPacketReplicationEngineEntry(
-                        P4RuntimeOuterClass.PacketReplicationEngineEntry.newBuilder()
-                                .setMulticastGroupEntry(CODECS.multicastGroupEntry().encodeKey(
-                                        (PiMulticastGroupEntryHandle) piHandle, null, pipeconf))
-                                .build())
-                        .build();
+            case PRE_ENTRY:
+                final PiPreEntryHandle preEntryHandle = (PiPreEntryHandle) piHandle;
+                switch (preEntryHandle.preEntryType()) {
+                    case MULTICAST_GROUP:
+                        return p4Entity.setPacketReplicationEngineEntry(
+                                P4RuntimeOuterClass.PacketReplicationEngineEntry.newBuilder()
+                                        .setMulticastGroupEntry(CODECS.multicastGroupEntry().encodeKey(
+                                                (PiMulticastGroupEntryHandle) piHandle, null, pipeconf))
+                                        .build())
+                                .build();
+                    case CLONE_SESSION:
+                        return p4Entity.setPacketReplicationEngineEntry(
+                                P4RuntimeOuterClass.PacketReplicationEngineEntry.newBuilder()
+                                        .setCloneSessionEntry(CODECS.cloneSessionEntry().encodeKey(
+                                                (PiCloneSessionEntryHandle) piHandle, null, pipeconf))
+                                        .build())
+                                .build();
+                    default:
+                        throw new CodecException(format(
+                                "Encoding of handle for %s of type %s is not supported",
+                                piHandle.entityType(),
+                                preEntryHandle.preEntryType()));
+                }
             case METER_CELL_CONFIG:
                 final PiMeterCellHandle meterCellHandle = (PiMeterCellHandle) piHandle;
                 switch (meterCellHandle.cellId().meterType()) {
@@ -101,7 +119,6 @@
                                 counterCellHandle.cellId().counterType()));
                 }
             case REGISTER_CELL:
-            case PRE_CLONE_SESSION_ENTRY:
             default:
                 throw new CodecException(format(
                         "Encoding of handle for %s not supported",
@@ -113,7 +130,7 @@
     protected PiHandle decode(
             P4RuntimeOuterClass.Entity message, Object ignored,
             PiPipeconf pipeconf, P4InfoBrowser browser)
-            throws CodecException, P4InfoBrowser.NotFoundException {
+            throws CodecException {
         throw new CodecException("Decoding of Entity to PiHandle is not supported");
     }
 }
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/MulticastGroupEntryCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/MulticastGroupEntryCodec.java
index 38080cc..bcc4555 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/MulticastGroupEntryCodec.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/MulticastGroupEntryCodec.java
@@ -16,16 +16,13 @@
 
 package org.onosproject.p4runtime.ctl.codec;
 
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
 import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
-import org.onosproject.net.pi.runtime.PiPreReplica;
 import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser;
 import p4.v1.P4RuntimeOuterClass;
-import p4.v1.P4RuntimeOuterClass.Replica;
 
-import static java.lang.String.format;
+import static org.onosproject.p4runtime.ctl.codec.Codecs.CODECS;
 
 /**
  * Codec for P4Runtime MulticastGroupEntry.
@@ -38,25 +35,12 @@
     protected P4RuntimeOuterClass.MulticastGroupEntry encode(
             PiMulticastGroupEntry piEntity, Object ignored,
             PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException {
-        final P4RuntimeOuterClass.MulticastGroupEntry.Builder msgBuilder =
-                P4RuntimeOuterClass.MulticastGroupEntry.newBuilder()
-                        .setMulticastGroupId(piEntity.groupId());
-        for (PiPreReplica replica : piEntity.replicas()) {
-            final int p4PortId;
-            try {
-                p4PortId = Math.toIntExact(replica.egressPort().toLong());
-            } catch (ArithmeticException e) {
-                throw new CodecException(format(
-                        "Cannot cast 64 bit port value '%s' to 32 bit",
-                        replica.egressPort()));
-            }
-            msgBuilder.addReplicas(
-                    Replica.newBuilder()
-                            .setEgressPort(p4PortId)
-                            .setInstance(replica.instanceId())
-                            .build());
-        }
-        return msgBuilder.build();
+        return P4RuntimeOuterClass.MulticastGroupEntry.newBuilder()
+                .setMulticastGroupId(piEntity.groupId())
+                .addAllReplicas(
+                        CODECS.preReplica().encodeAll(
+                                piEntity.replicas(), null, pipeconf))
+                .build();
     }
 
     @Override
@@ -78,13 +62,12 @@
     @Override
     protected PiMulticastGroupEntry decode(
             P4RuntimeOuterClass.MulticastGroupEntry message, Object ignored,
-            PiPipeconf pipeconf, P4InfoBrowser browser) {
-        final PiMulticastGroupEntry.Builder piEntryBuilder = PiMulticastGroupEntry.builder();
-        piEntryBuilder.withGroupId(message.getMulticastGroupId());
-        message.getReplicasList().stream()
-                .map(r -> new PiPreReplica(
-                        PortNumber.portNumber(r.getEgressPort()), r.getInstance()))
-                .forEach(piEntryBuilder::addReplica);
-        return piEntryBuilder.build();
+            PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException {
+        return PiMulticastGroupEntry.builder()
+                .withGroupId(message.getMulticastGroupId())
+                .addReplicas(
+                        CODECS.preReplica().decodeAll(
+                                message.getReplicasList(), null, pipeconf))
+                .build();
     }
 }
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java
new file mode 100644
index 0000000..7402b14
--- /dev/null
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/codec/PreReplicaCodec.java
@@ -0,0 +1,61 @@
+/*
+ * 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 org.onosproject.net.PortNumber;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.runtime.PiPreReplica;
+import org.onosproject.p4runtime.ctl.utils.P4InfoBrowser;
+import p4.v1.P4RuntimeOuterClass;
+
+import static java.lang.String.format;
+
+/**
+ * Codec for P4Runtime PRE Replica.
+ */
+public class PreReplicaCodec extends AbstractCodec<PiPreReplica,
+        P4RuntimeOuterClass.Replica, Object> {
+
+    @Override
+    protected P4RuntimeOuterClass.Replica encode(
+            PiPreReplica replica, Object ignore,
+            PiPipeconf pipeconf, P4InfoBrowser browser)
+            throws CodecException, P4InfoBrowser.NotFoundException {
+        final int p4PortId;
+        try {
+            p4PortId = Math.toIntExact(replica.egressPort().toLong());
+        } catch (ArithmeticException e) {
+            throw new CodecException(format(
+                    "Cannot cast 64 bit port value '%s' to 32 bit",
+                    replica.egressPort()));
+        }
+        return P4RuntimeOuterClass.Replica.newBuilder()
+                .setEgressPort(p4PortId)
+                .setInstance(replica.instanceId())
+                .build();
+    }
+
+    @Override
+    protected PiPreReplica decode(
+            P4RuntimeOuterClass.Replica message, Object ignore,
+            PiPipeconf pipeconf, P4InfoBrowser browser)
+            throws CodecException, P4InfoBrowser.NotFoundException {
+        return new PiPreReplica(
+                PortNumber.portNumber(message.getEgressPort()),
+                message.getInstance());
+    }
+}