More robust P4Runtime group handling

This patch solves the PENDING_UPDATE and PENDING_ADD_RETRY issue
observed on the ONS EU topology.

The P4Runtime action profile group handling has been re-implemented to
be robust against inconsistencies of the device mirror, which is now
periodically synchronized with the device state. Similarly, we implement
a routine in the P4RuntimeClient to cleanup unused action profile
members.

This patch includes also:
-  Refactor PI handle classes to allow creating handles without the
entity instance
- Use list instead of collections in P4RuntimeClient methods, as order
of updates sent and/or entities received from the device is important

Change-Id: I2e7964ce90f43d66680131b47ab52aca32ab55d2
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 f53dca8..84678dc 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
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017-present Open Networking Foundation
+ * 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.
@@ -18,545 +18,92 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.Striped;
-import org.onlab.util.SharedExecutors;
-import org.onosproject.drivers.p4runtime.mirror.P4RuntimeGroupMirror;
-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.DefaultGroupDescription;
+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;
-import org.onosproject.net.group.GroupStore;
-import org.onosproject.net.pi.model.PiActionProfileId;
-import org.onosproject.net.pi.model.PiActionProfileModel;
-import org.onosproject.net.pi.runtime.PiActionGroup;
-import org.onosproject.net.pi.runtime.PiActionGroupHandle;
-import org.onosproject.net.pi.runtime.PiActionGroupMember;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntry;
-import org.onosproject.net.pi.runtime.PiMulticastGroupEntryHandle;
-import org.onosproject.net.pi.service.PiGroupTranslator;
-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 org.slf4j.Logger;
 
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.locks.Lock;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static java.lang.String.format;
-import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.DELETE;
-import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.INSERT;
-import static org.onosproject.p4runtime.api.P4RuntimeClient.WriteOperationType.MODIFY;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
- * Implementation of the group programmable behaviour for P4Runtime.
- * <p>
- * This implementation distinguishes between ALL groups, and other types. ALL
- * groups are handled via PRE multicast group programming, while other types are
- * handled via action profile group programming.
+ * Implementation of GroupProgrammable for P4Runtime devices that uses two
+ * different implementation of the same behavior to handle both action profile
+ * groups and multicast groups.
  */
 public class P4RuntimeGroupProgrammable
-        extends AbstractP4RuntimeHandlerBehaviour
-        implements GroupProgrammable {
+        extends AbstractHandlerBehaviour implements GroupProgrammable {
 
-    private static final String ACT_GRP_MEMS_STR = "action group members";
-    private static final String DELETE_STR = "delete";
-    private static final String ACT_GRP_STR = "action group";
-    private static final String INSERT_STR = "insert";
-    private static final String MODIFY_STR = "modify";
+    private final Logger log = getLogger(this.getClass());
 
-    private static final Logger log = getLogger(P4RuntimeGroupProgrammable.class);
-
-    // If true, we ignore re-installing groups that are already known in the
-    // device mirror.
-    private static final String CHECK_MIRROR_BEFORE_UPDATE = "checkMirrorBeforeUpdate";
-    private static final boolean DEFAULT_CHECK_MIRROR_BEFORE_UPDATE = true;
-
-    // If true, we avoid querying the device and return what's already known by
-    // the ONOS store.
-    private static final String READ_ACTION_GROUPS_FROM_MIRROR = "actionGroupReadFromMirror";
-    private static final boolean DEFAULT_READ_ACTION_GROUPS_FROM_MIRROR = false;
-
-    protected GroupStore groupStore;
-    private P4RuntimeGroupMirror groupMirror;
-    private PiGroupTranslator groupTranslator;
-    private P4RuntimeMulticastGroupMirror mcGroupMirror;
-    private PiMulticastGroupTranslator mcGroupTranslator;
-
-    // Needed to synchronize operations over the same group.
-    private static final Striped<Lock> STRIPED_LOCKS = Striped.lock(30);
-
-    @Override
-    protected boolean setupBehaviour() {
-        if (!super.setupBehaviour()) {
-            return false;
+    private void doPerformGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
+        // TODO: fix GroupProgrammable API, passing the device ID is ambiguous
+        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();
+        groupOps.operations().forEach(op -> {
+            if (op.groupType().equals(GroupDescription.Type.ALL)) {
+                multicastGroups.add(op);
+            } else {
+                actionGroups.add(op);
+            }
+        });
+        if (!actionGroups.isEmpty()) {
+            actionProgrammable().performGroupOperation(
+                    deviceId, new GroupOperations(actionGroups));
         }
-        groupMirror = this.handler().get(P4RuntimeGroupMirror.class);
-        mcGroupMirror = this.handler().get(P4RuntimeMulticastGroupMirror.class);
-        groupStore = handler().get(GroupStore.class);
-        groupTranslator = piTranslationService.groupTranslator();
-        mcGroupTranslator = piTranslationService.multicastGroupTranslator();
-        return true;
+        if (!multicastGroups.isEmpty()) {
+            multicastProgrammable().performGroupOperation(
+                    deviceId, new GroupOperations(multicastGroups));
+        }
+    }
+
+    private Collection<Group> doGetGroups() {
+        return new ImmutableList.Builder<Group>()
+                .addAll(actionProgrammable().getGroups())
+                .addAll(multicastProgrammable().getGroups())
+                .build();
+    }
+
+    private P4RuntimeActionGroupProgrammable actionProgrammable() {
+        P4RuntimeActionGroupProgrammable prog = new P4RuntimeActionGroupProgrammable();
+        prog.setData(data());
+        prog.setHandler(handler());
+        return prog;
+    }
+
+    private P4RuntimeMulticastGroupProgrammable multicastProgrammable() {
+        P4RuntimeMulticastGroupProgrammable prog = new P4RuntimeMulticastGroupProgrammable();
+        prog.setData(data());
+        prog.setHandler(handler());
+        return prog;
     }
 
     @Override
-    public void performGroupOperation(DeviceId deviceId,
-                                      GroupOperations groupOps) {
-        if (!setupBehaviour()) {
-            return;
+    public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
+        try {
+            doPerformGroupOperation(deviceId, groupOps);
+        } catch (Throwable ex) {
+            log.error("Unhandled exception on performGroupOperation", ex);
         }
-
-        // TODO: fix GroupProgrammable API, passing the device ID is ambiguous
-        checkArgument(deviceId.equals(this.deviceId),
-                      "passed deviceId must be the same assigned to this behavior");
-
-        groupOps.operations().forEach(op -> {
-            // ONOS-7785 We need app cookie (action profile id) from the group
-            Group groupOnStore = groupStore.getGroup(deviceId, op.groupId());
-            GroupDescription groupDesc = new DefaultGroupDescription(deviceId,
-                                                                     op.groupType(),
-                                                                     op.buckets(),
-                                                                     groupOnStore.appCookie(),
-                                                                     op.groupId().id(),
-                                                                     groupOnStore.appId());
-            DefaultGroup groupToApply = new DefaultGroup(op.groupId(), groupDesc);
-            if (op.groupType().equals(GroupDescription.Type.ALL)) {
-                processMcGroupOp(groupToApply, op.opType());
-            } else {
-
-                processActionGroupOp(groupToApply, op.opType());
-            }
-        });
     }
 
     @Override
     public Collection<Group> getGroups() {
-        if (!setupBehaviour()) {
+        try {
+            return doGetGroups();
+        } catch (Throwable ex) {
+            log.error("Unhandled exception on getGroups", ex);
             return Collections.emptyList();
         }
-        return new ImmutableList.Builder<Group>()
-                .addAll(getActionGroups())
-                .addAll(getMcGroups()).build();
-    }
-
-    private Collection<Group> getActionGroups() {
-
-        if (driverBoolProperty(READ_ACTION_GROUPS_FROM_MIRROR,
-                               DEFAULT_READ_ACTION_GROUPS_FROM_MIRROR)) {
-            return getActionGroupsFromMirror();
-        }
-
-        final Collection<PiActionGroup> piGroups = pipeconf.pipelineModel()
-                .actionProfiles()
-                .stream()
-                .map(PiActionProfileModel::id)
-                .flatMap(this::streamPiGroupsFromDevice)
-                .collect(Collectors.toList());
-
-        if (piGroups.isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        final List<Group> result = Lists.newArrayList();
-        final List<PiActionGroup> inconsistentGroups = Lists.newArrayList();
-
-        for (PiActionGroup piGroupOnDevice : piGroups) {
-            final Group group = forgeGroupEntry(piGroupOnDevice);
-            if (group == null) {
-                // Entry is on device but unknown to translation service or
-                // device mirror. Inconsistent. Mark for removal.
-                inconsistentGroups.add(piGroupOnDevice);
-            } else {
-                result.add(group);
-            }
-        }
-        // Trigger clean up of inconsistent entries (is any).
-        // TODO: make this behaviour configurable, in some cases it's fine for
-        // the device to have groups that were not installed by us.
-        if (!inconsistentGroups.isEmpty()) {
-            SharedExecutors.getSingleThreadExecutor().execute(
-                    () -> cleanUpInconsistentGroups(inconsistentGroups));
-        }
-        return result;
-    }
-
-    private Collection<Group> getActionGroupsFromMirror() {
-        return groupMirror.getAll(deviceId).stream()
-                .map(TimedEntry::entry)
-                .map(this::forgeGroupEntry)
-                .filter(Objects::nonNull)
-                .collect(Collectors.toList());
-    }
-
-    private void cleanUpInconsistentGroups(Collection<PiActionGroup> piGroups) {
-        log.warn("Found {} inconsistent groups on {}, removing them...",
-                 piGroups.size(), deviceId);
-        piGroups.forEach(piGroup -> {
-            log.debug(piGroup.toString());
-            // Per-piGroup lock.
-            final PiActionGroupHandle handle = PiActionGroupHandle.of(deviceId, piGroup);
-            STRIPED_LOCKS.get(handle).lock();
-            try {
-                processActionGroup(handle, piGroup, null, null,
-                                   GroupOperation.Type.DELETE);
-            } finally {
-                STRIPED_LOCKS.get(handle).unlock();
-            }
-        });
-    }
-
-    private Collection<Group> getMcGroups() {
-        // TODO: missing support for reading multicast groups is ready 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 processActionGroupOp(Group pdGroup, GroupOperation.Type opType) {
-        final PiActionGroup piGroup;
-        try {
-            piGroup = groupTranslator.translate(pdGroup, pipeconf);
-        } catch (PiTranslationException e) {
-            log.warn("Unable to translate group, aborting {} operation: {} [{}]",
-                     opType, e.getMessage(), pdGroup);
-            return;
-        }
-        final PiActionGroupHandle handle = PiActionGroupHandle.of(deviceId, piGroup);
-        final PiActionGroup groupOnDevice = groupMirror.get(handle) == null
-                ? null : groupMirror.get(handle).entry();
-        // Per-piGroup lock.
-        final Lock lock = STRIPED_LOCKS.get(handle);
-        lock.lock();
-        try {
-            processActionGroup(handle, piGroup,
-                               groupOnDevice, pdGroup, opType);
-        } finally {
-            lock.unlock();
-        }
-    }
-
-    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 processActionGroup(PiActionGroupHandle handle,
-                                    PiActionGroup groupToApply,
-                                    PiActionGroup groupOnDevice,
-                                    Group pdGroup, GroupOperation.Type operationType) {
-        switch (operationType) {
-            case ADD:
-                if (groupOnDevice != null) {
-                    log.warn("Requested to ADD group {} on {}, but a group " +
-                                     "with the same ID already exists, will " +
-                                     "MODIFY instead",
-                             groupToApply.id(), deviceId);
-                    log.debug("To apply: {}", groupToApply);
-                    log.debug("On device: {}", groupOnDevice);
-                    processActionGroup(handle, groupToApply, groupOnDevice,
-                                       pdGroup, GroupOperation.Type.MODIFY);
-                    return;
-                }
-                if (writeGroupToDevice(groupToApply)) {
-                    groupMirror.put(handle, groupToApply);
-                    groupTranslator.learn(handle, new PiTranslatedEntity<>(
-                            pdGroup, groupToApply, handle));
-                }
-                return;
-            case MODIFY:
-                if (groupOnDevice == null) {
-                    log.warn("Requested to MODIFY group {} on {}, but no " +
-                                     "such group exists on the device, " +
-                                     "will ADD instead",
-                             groupToApply.id(), deviceId);
-                    processActionGroup(handle, groupToApply, null,
-                                       pdGroup, GroupOperation.Type.ADD);
-                    return;
-                }
-                if (driverBoolProperty(CHECK_MIRROR_BEFORE_UPDATE,
-                                       DEFAULT_CHECK_MIRROR_BEFORE_UPDATE)
-                        && groupOnDevice.equals(groupToApply)) {
-                    // Group on device has the same members, ignore operation.
-                    return;
-                }
-                if (modifyGroupFromDevice(groupToApply, groupOnDevice)) {
-                    groupMirror.put(handle, groupToApply);
-                    groupTranslator.learn(handle, new PiTranslatedEntity<>(
-                            pdGroup, groupToApply, handle));
-                }
-                return;
-            case DELETE:
-                if (deleteGroupFromDevice(groupToApply)) {
-                    groupMirror.remove(handle);
-                    groupTranslator.forget(handle);
-                }
-                break;
-            default:
-                log.error("Unknwon group operation type {}, cannot process group", operationType);
-                break;
-        }
-    }
-
-    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 groupOnDevic) 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.WriteOperationType opType) {
-        return getFutureWithDeadline(
-                client.writePreMulticastGroupEntries(
-                        Collections.singleton(group), opType),
-                "performing multicast group " + opType, false);
-    }
-
-    private boolean mcGroupApply(PiMulticastGroupEntryHandle handle,
-                                 PiMulticastGroupEntry piGroup,
-                                 Group pdGroup,
-                                 P4RuntimeClient.WriteOperationType 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 boolean modifyGroupFromDevice(PiActionGroup groupToApply, PiActionGroup groupOnDevice) {
-        PiActionProfileId groupProfileId = groupToApply.actionProfileId();
-        Collection<PiActionGroupMember> membersToRemove = Sets.newHashSet(groupOnDevice.members());
-        membersToRemove.removeAll(groupToApply.members());
-        Collection<PiActionGroupMember> membersToAdd = Sets.newHashSet(groupToApply.members());
-        membersToAdd.removeAll(groupOnDevice.members());
-
-        if (!membersToAdd.isEmpty() &&
-                !completeFuture(client.writeActionGroupMembers(groupProfileId, membersToAdd, INSERT, pipeconf),
-                                ACT_GRP_MEMS_STR, INSERT_STR)) {
-            // remove what we added
-            completeFuture(client.writeActionGroupMembers(groupProfileId, membersToAdd, DELETE, pipeconf),
-                           ACT_GRP_MEMS_STR, INSERT_STR);
-            return false;
-        }
-
-        if (!completeFuture(client.writeActionGroup(groupToApply, MODIFY, pipeconf),
-                            ACT_GRP_STR, MODIFY_STR)) {
-            // recover group information
-            completeFuture(client.writeActionGroup(groupOnDevice, MODIFY, pipeconf),
-                           ACT_GRP_STR, MODIFY_STR);
-            // remove what we added
-            completeFuture(client.writeActionGroupMembers(groupProfileId, membersToAdd, DELETE, pipeconf),
-                           ACT_GRP_MEMS_STR, INSERT_STR);
-            return false;
-        }
-
-        if (!membersToRemove.isEmpty() &&
-                !completeFuture(client.writeActionGroupMembers(groupProfileId, membersToRemove, DELETE, pipeconf),
-                                ACT_GRP_MEMS_STR, DELETE_STR)) {
-            // add what we removed
-            completeFuture(client.writeActionGroupMembers(groupProfileId, membersToRemove, INSERT, pipeconf),
-                           ACT_GRP_MEMS_STR, DELETE_STR);
-            // recover group information
-            completeFuture(client.writeActionGroup(groupOnDevice, MODIFY, pipeconf),
-                           ACT_GRP_STR, MODIFY_STR);
-            // remove what we added
-            completeFuture(client.writeActionGroupMembers(groupProfileId, membersToAdd, DELETE, pipeconf),
-                           ACT_GRP_MEMS_STR, INSERT_STR);
-            return false;
-        }
-
-        return true;
-    }
-
-    private boolean writeGroupToDevice(PiActionGroup groupToApply) {
-        // First insert members, then group.
-        // The operation is deemed successful if both operations are successful.
-        // FIXME: add transactional semantics, i.e. remove members if group fails.
-        final boolean membersSuccess = completeFuture(
-                client.writeActionGroupMembers(groupToApply.actionProfileId(),
-                                               groupToApply.members(),
-                                               INSERT, pipeconf),
-                ACT_GRP_MEMS_STR, INSERT_STR);
-        return membersSuccess && completeFuture(
-                client.writeActionGroup(groupToApply, INSERT, pipeconf),
-                ACT_GRP_STR, INSERT_STR);
-    }
-
-    private boolean deleteGroupFromDevice(PiActionGroup piActionGroup) {
-        // First delete group, then members.
-        // The operation is deemed successful if both operations are successful.
-        final boolean groupSuccess = completeFuture(
-                client.writeActionGroup(piActionGroup, DELETE, pipeconf),
-                ACT_GRP_STR, DELETE_STR);
-        return groupSuccess && completeFuture(
-                client.writeActionGroupMembers(piActionGroup.actionProfileId(),
-                                               piActionGroup.members(),
-                                               DELETE, pipeconf),
-                ACT_GRP_MEMS_STR, DELETE_STR);
-    }
-
-    private boolean completeFuture(CompletableFuture<Boolean> completableFuture,
-                                   String topic, String action) {
-        return getFutureWithDeadline(
-                completableFuture, format("performing %s %s", action, topic), false);
-    }
-
-    private Stream<PiActionGroup> streamPiGroupsFromDevice(PiActionProfileId actProfId) {
-        // Read PI groups and return original PD one.
-        // TODO: implement P4Runtime client call to read all groups with one call
-        // Good is pipeline has multiple action profiles.
-        final Collection<PiActionGroup> groups = getFutureWithDeadline(
-                client.dumpGroups(actProfId, pipeconf),
-                "dumping groups", Collections.emptyList());
-        return groups.stream();
-    }
-
-    private Group forgeGroupEntry(PiActionGroup piGroup) {
-        final PiActionGroupHandle handle = PiActionGroupHandle.of(deviceId, piGroup);
-        final Optional<PiTranslatedEntity<Group, PiActionGroup>>
-                translatedEntity = groupTranslator.lookup(handle);
-        final TimedEntry<PiActionGroup> timedEntry = groupMirror.get(handle);
-        // Is entry consistent with our state?
-        if (!translatedEntity.isPresent()) {
-            log.warn("Group handle not found in translation store: {}", handle);
-            return null;
-        }
-        if (timedEntry == null) {
-            // Don't bother logging more than debug, most probably it's the EC
-            // map backing the store that has not received all the updates yet.
-            log.debug("Group handle not found in device mirror: {}", handle);
-            return null;
-        }
-        return addedGroup(translatedEntity.get().original(), timedEntry.lifeSec());
-    }
-
-    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;
     }
 }