Search in sources :

Example 1 with PiActionProfileGroupHandle

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

the class P4RuntimeActionGroupProgrammable method checkAndForgeGroupEntry.

private Group checkAndForgeGroupEntry(PiActionProfileGroup piGroupOnDevice, Map<PiActionProfileMemberHandle, PiActionProfileMember> membersOnDevice) {
    final PiActionProfileGroupHandle handle = PiActionProfileGroupHandle.of(deviceId, piGroupOnDevice);
    final Optional<PiTranslatedEntity<Group, PiActionProfileGroup>> translatedEntity = groupTranslator.lookup(handle);
    final TimedEntry<PiActionProfileGroup> mirrorEntry = groupMirror.get(handle);
    // by the translation store.
    if (!translatedEntity.isPresent()) {
        log.warn("Group not found in translation store: {}", handle);
        return null;
    }
    final PiActionProfileGroup piGroupFromStore = translatedEntity.get().translated();
    if (!piGroupFromStore.equals(piGroupOnDevice)) {
        log.warn("Group on device {} is different from the one in " + "translation store: {} [device={}, store={}]", deviceId, handle, piGroupOnDevice, piGroupFromStore);
        return null;
    }
    // found on the device.
    if (!validateGroupMembers(piGroupFromStore, membersOnDevice)) {
        log.warn("Group on device {} refers to members that are different " + "than those found in translation store: {}", deviceId, handle);
        return null;
    }
    if (mirrorEntry == null) {
        log.warn("Group handle not found in device mirror: {}", handle);
        return null;
    }
    // Check that members from device are the same as in the translated group.
    return addedGroup(translatedEntity.get().original(), mirrorEntry.lifeSec());
}
Also used : PiTranslatedEntity(org.onosproject.net.pi.service.PiTranslatedEntity) PiActionProfileGroupHandle(org.onosproject.net.pi.runtime.PiActionProfileGroupHandle) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup)

Example 2 with PiActionProfileGroupHandle

use of org.onosproject.net.pi.runtime.PiActionProfileGroupHandle 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)

Example 3 with PiActionProfileGroupHandle

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

the class P4RuntimeActionGroupProgrammable method processPdGroup.

private void processPdGroup(Group pdGroup, GroupOperation.Type opType) {
    // Translate.
    final PiActionProfileGroup piGroup;
    try {
        piGroup = groupTranslator.translate(pdGroup, pipeconf);
    } catch (PiTranslationException e) {
        log.warn("Unable to translate group, aborting {} operation: {} [{}]", opType, e.getMessage(), pdGroup);
        return;
    }
    final Operation operation = opType.equals(GroupOperation.Type.DELETE) ? Operation.REMOVE : Operation.APPLY;
    final PiActionProfileGroupHandle handle = piGroup.handle(deviceId);
    // Update translation store.
    if (operation.equals(Operation.APPLY)) {
        groupTranslator.learn(handle, new PiTranslatedEntity<>(pdGroup, piGroup, handle));
    } else {
        groupTranslator.forget(handle);
    }
    // Submit write and forget about it.
    asyncWritePiGroup(piGroup, handle, operation);
}
Also used : PiActionProfileGroupHandle(org.onosproject.net.pi.runtime.PiActionProfileGroupHandle) GroupOperation(org.onosproject.net.group.GroupOperation) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup)

Aggregations

PiActionProfileGroup (org.onosproject.net.pi.runtime.PiActionProfileGroup)3 PiActionProfileGroupHandle (org.onosproject.net.pi.runtime.PiActionProfileGroupHandle)3 GroupOperation (org.onosproject.net.group.GroupOperation)2 PiTranslatedEntity (org.onosproject.net.pi.service.PiTranslatedEntity)2 PiTranslationException (org.onosproject.net.pi.service.PiTranslationException)2 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Striped (com.google.common.util.concurrent.Striped)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Lock (java.util.concurrent.locks.Lock)1 Collectors (java.util.stream.Collectors)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 P4RuntimeActionProfileGroupMirror (org.onosproject.drivers.p4runtime.mirror.P4RuntimeActionProfileGroupMirror)1