Search in sources :

Example 6 with PiActionProfileGroup

use of org.onosproject.net.pi.runtime.PiActionProfileGroup in project onos by opennetworkinglab.

the class P4RuntimeActionGroupProgrammable method getGroups.

@Override
public Collection<Group> getGroups() {
    if (!setupBehaviour("getGroups()")) {
        return Collections.emptyList();
    }
    if (driverBoolProperty(READ_ACTION_GROUPS_FROM_MIRROR, DEFAULT_READ_ACTION_GROUPS_FROM_MIRROR)) {
        return getGroupsFromMirror();
    }
    // Dump groups and members from device for all action profiles.
    final P4RuntimeReadClient.ReadRequest request = client.read(p4DeviceId, pipeconf);
    pipeconf.pipelineModel().actionProfiles().stream().filter(piActionProfileModel -> piActionProfileModel.tables().stream().map(tableId -> pipeconf.pipelineModel().table(tableId)).allMatch(piTableModel -> piTableModel.isPresent() && !piTableModel.get().oneShotOnly())).map(PiActionProfileModel::id).forEach(id -> request.actionProfileGroups(id).actionProfileMembers(id));
    final P4RuntimeReadClient.ReadResponse response = request.submitSync();
    if (!response.isSuccess()) {
        // Error at client level.
        return Collections.emptyList();
    }
    final Collection<PiActionProfileGroup> groupsOnDevice = response.all(PiActionProfileGroup.class);
    final Map<PiActionProfileMemberHandle, PiActionProfileMember> membersOnDevice = response.all(PiActionProfileMember.class).stream().collect(toMap(m -> m.handle(deviceId), m -> m));
    // Sync mirrors.
    groupMirror.sync(deviceId, groupsOnDevice);
    memberMirror.sync(deviceId, membersOnDevice.values());
    // Retrieve the original PD group before translation.
    final List<Group> result = Lists.newArrayList();
    final List<PiActionProfileGroup> groupsToRemove = Lists.newArrayList();
    final Set<PiActionProfileMemberHandle> memberHandlesToKeep = Sets.newHashSet();
    for (PiActionProfileGroup piGroup : groupsOnDevice) {
        final Group pdGroup = checkAndForgeGroupEntry(piGroup, membersOnDevice);
        if (pdGroup == null) {
            // Entry is on device but is inconsistent with controller state.
            // Mark for removal.
            groupsToRemove.add(piGroup);
        } else {
            result.add(pdGroup);
            // Keep track of member handles used in groups.
            piGroup.members().stream().map(m -> PiActionProfileMemberHandle.of(deviceId, piGroup.actionProfile(), m.id())).forEach(memberHandlesToKeep::add);
        }
    }
    // Trigger clean up of inconsistent groups and members (if any). Also
    // take care of removing any orphan member, e.g. from a
    // partial/unsuccessful group insertion.
    final Set<PiActionProfileMemberHandle> memberHandlesToRemove = Sets.difference(membersOnDevice.keySet(), memberHandlesToKeep);
    final Set<PiActionProfileGroupHandle> groupHandlesToRemove = groupsToRemove.stream().map(g -> g.handle(deviceId)).collect(toSet());
    if (groupHandlesToRemove.size() + memberHandlesToRemove.size() > 0) {
        log.warn("Cleaning up {} action profile groups and " + "{} members on {}...", groupHandlesToRemove.size(), memberHandlesToRemove.size(), deviceId);
        client.write(p4DeviceId, pipeconf).delete(groupHandlesToRemove).delete(memberHandlesToRemove).submit().whenComplete((r, ex) -> {
            if (ex != null) {
                log.error("Exception removing inconsistent group/members", ex);
            } else {
                log.debug("Completed removal of inconsistent " + "groups/members ({} of {} updates succeeded)", r.success().size(), r.all().size());
                groupMirror.applyWriteResponse(r);
                memberMirror.applyWriteResponse(r);
            }
        });
    }
    // Done.
    return result;
}
Also used : P4RuntimeReadClient(org.onosproject.p4runtime.api.P4RuntimeReadClient) PiActionProfileGroupHandle(org.onosproject.net.pi.runtime.PiActionProfileGroupHandle) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupOperation(org.onosproject.net.group.GroupOperation) P4RuntimeActionProfileGroupMirror(org.onosproject.drivers.p4runtime.mirror.P4RuntimeActionProfileGroupMirror) Group(org.onosproject.net.group.Group) PiEntity(org.onosproject.net.pi.runtime.PiEntity) GroupStore(org.onosproject.net.group.GroupStore) GroupProgrammable(org.onosproject.net.group.GroupProgrammable) Lists(com.google.common.collect.Lists) Collectors.toMap(java.util.stream.Collectors.toMap) PiGroupTranslator(org.onosproject.net.pi.service.PiGroupTranslator) Map(java.util.Map) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) GroupOperations(org.onosproject.net.group.GroupOperations) Collectors.toSet(java.util.stream.Collectors.toSet) PiActionProfileMemberHandle(org.onosproject.net.pi.runtime.PiActionProfileMemberHandle) Striped(com.google.common.util.concurrent.Striped) PiTranslatedEntity(org.onosproject.net.pi.service.PiTranslatedEntity) P4RuntimeReadClient(org.onosproject.p4runtime.api.P4RuntimeReadClient) Collection(java.util.Collection) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) Set(java.util.Set) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) PiHandle(org.onosproject.net.pi.runtime.PiHandle) Objects(java.util.Objects) TimedEntry(org.onosproject.drivers.p4runtime.mirror.TimedEntry) List(java.util.List) Lock(java.util.concurrent.locks.Lock) P4RuntimeActionProfileMemberMirror(org.onosproject.drivers.p4runtime.mirror.P4RuntimeActionProfileMemberMirror) P4RuntimeMirror(org.onosproject.drivers.p4runtime.mirror.P4RuntimeMirror) Optional(java.util.Optional) PiActionProfileModel(org.onosproject.net.pi.model.PiActionProfileModel) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Collections(java.util.Collections) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) PiActionProfileGroupHandle(org.onosproject.net.pi.runtime.PiActionProfileGroupHandle) PiActionProfileMemberHandle(org.onosproject.net.pi.runtime.PiActionProfileMemberHandle)

Aggregations

PiActionProfileGroup (org.onosproject.net.pi.runtime.PiActionProfileGroup)6 PiActionProfileGroupHandle (org.onosproject.net.pi.runtime.PiActionProfileGroupHandle)3 PiActionProfileMember (org.onosproject.net.pi.runtime.PiActionProfileMember)3 PiTranslationException (org.onosproject.net.pi.service.PiTranslationException)3 Sets (com.google.common.collect.Sets)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Test (org.junit.Test)2 Group (org.onosproject.net.group.Group)2 GroupDescription (org.onosproject.net.group.GroupDescription)2 GroupOperation (org.onosproject.net.group.GroupOperation)2 PiActionProfileModel (org.onosproject.net.pi.model.PiActionProfileModel)2 PiTranslatedEntity (org.onosproject.net.pi.service.PiTranslatedEntity)2 Lists (com.google.common.collect.Lists)1 EqualsTester (com.google.common.testing.EqualsTester)1 Striped (com.google.common.util.concurrent.Striped)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1