Search in sources :

Example 1 with ACTION

use of org.onosproject.net.pi.runtime.PiTableAction.Type.ACTION in project onos by opennetworkinglab.

the class PiGroupTranslatorImpl method translate.

/**
 * Returns a PI action profile group equivalent to the given group, for the
 * given pipeconf and device.
 *
 * @param group    group
 * @param pipeconf pipeconf
 * @param device   device
 * @return PI action profile group
 * @throws PiTranslationException if the group cannot be translated
 */
static PiActionProfileGroup translate(Group group, PiPipeconf pipeconf, Device device) throws PiTranslationException {
    if (!SUPPORTED_GROUP_TYPES.contains(group.type())) {
        throw new PiTranslationException(format("group type %s not supported", group.type()));
    }
    // TODO: define proper field in group class.
    if (!(group.appCookie() instanceof PiGroupKey)) {
        throw new PiTranslationException("group app cookie is not PI (class should be PiGroupKey)");
    }
    final PiGroupKey groupKey = (PiGroupKey) group.appCookie();
    final PiActionProfileId actionProfileId = groupKey.actionProfileId();
    // Check validity of action profile against pipeconf.
    final PiActionProfileModel actionProfileModel = pipeconf.pipelineModel().actionProfiles(actionProfileId).orElseThrow(() -> new PiTranslationException(format("no such action profile '%s'", actionProfileId)));
    if (!actionProfileModel.hasSelector()) {
        throw new PiTranslationException(format("action profile '%s' does not support dynamic selection", actionProfileId));
    }
    // Check if the table associated with the action profile supports only
    // one-shot action profile programming.
    boolean isTableOneShot = actionProfileModel.tables().stream().map(tableId -> pipeconf.pipelineModel().table(tableId)).allMatch(piTableModel -> piTableModel.isPresent() && piTableModel.get().oneShotOnly());
    if (isTableOneShot) {
        throw new PiTranslationException(format("Table associated to action profile '%s' supports only one-shot action profile programming", actionProfileId));
    }
    // Check group validity.
    if (actionProfileModel.maxGroupSize() > 0 && group.buckets().buckets().size() > actionProfileModel.maxGroupSize()) {
        throw new PiTranslationException(format("too many buckets, max group size for action profile '%s' is %d", actionProfileId, actionProfileModel.maxGroupSize()));
    }
    // If not INDIRECT, we set the maximum group size as specified in the
    // model, however this might be highly inefficient for some HW targets
    // which pre-allocate resources for the whole group.
    final int maxGroupSize = group.type() == GroupDescription.Type.INDIRECT ? 1 : actionProfileModel.maxGroupSize();
    final PiActionProfileGroup.Builder piActionGroupBuilder = PiActionProfileGroup.builder().withId(PiActionProfileGroupId.of(group.id().id())).withActionProfileId(groupKey.actionProfileId()).withMaxSize(maxGroupSize);
    // Translate group buckets to PI group members
    final PiPipelineInterpreter interpreter = getInterpreterOrNull(device, pipeconf);
    short bucketIdx = 0;
    for (GroupBucket bucket : group.buckets().buckets()) {
        /*
            FIXME: the way member IDs are computed can cause collisions!
            Problem: In P4Runtime action profile members, i.e. action buckets,
            are associated to a numeric ID chosen at member insertion time. This
            ID must be unique for the whole action profile (i.e. the group table
            in OpenFlow). In ONOS, GroupBucket doesn't specify any ID.

            Solutions:
            - Change GroupBucket API to force application wanting to perform
            group operations to specify a member id.
            - Maintain state to dynamically allocate/deallocate member IDs, e.g.
            in a dedicated service, or in a P4Runtime Group Provider.

            Hack: Statically derive member ID by combining groupId and position
            of the bucket in the list.
             */
        final int memberId = Objects.hash(group.id(), bucketIdx);
        if (memberId == 0) {
            throw new PiTranslationException("GroupBucket produces PiActionProfileMember " + "with invalid ID 0");
        }
        bucketIdx++;
        final PiTableAction tableAction = translateTreatment(bucket.treatment(), interpreter, groupKey.tableId(), pipeconf.pipelineModel());
        if (tableAction == null) {
            throw new PiTranslationException("bucket treatment translator returned null");
        }
        if (tableAction.type() != ACTION) {
            throw new PiTranslationException(format("action of type '%s' cannot be used in action profile members", tableAction.type()));
        }
        final PiActionProfileMember member = PiActionProfileMember.builder().forActionProfile(groupKey.actionProfileId()).withId(PiActionProfileMemberId.of(memberId)).withAction((PiAction) tableAction).build();
        // NOTE Indirect groups have weight set to -1 which is not supported
        // by P4RT - setting to 1 to avoid problems with the p4rt server.
        final int weight = group.type() == GroupDescription.Type.INDIRECT ? 1 : bucket.weight();
        piActionGroupBuilder.addMember(member, weight);
    }
    return piActionGroupBuilder.build();
}
Also used : PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) PiUtils.getInterpreterOrNull(org.onosproject.net.pi.impl.PiUtils.getInterpreterOrNull) Device(org.onosproject.net.Device) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) Set(java.util.Set) GroupBucket(org.onosproject.net.group.GroupBucket) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Group(org.onosproject.net.group.Group) Objects(java.util.Objects) PiAction(org.onosproject.net.pi.runtime.PiAction) PiFlowRuleTranslatorImpl.translateTreatment(org.onosproject.net.pi.impl.PiFlowRuleTranslatorImpl.translateTreatment) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) ACTION(org.onosproject.net.pi.runtime.PiTableAction.Type.ACTION) PiActionProfileModel(org.onosproject.net.pi.model.PiActionProfileModel) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) PiActionProfileId(org.onosproject.net.pi.model.PiActionProfileId) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiActionProfileId(org.onosproject.net.pi.model.PiActionProfileId) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) PiAction(org.onosproject.net.pi.runtime.PiAction) PiActionProfileModel(org.onosproject.net.pi.model.PiActionProfileModel) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter)

Aggregations

Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Device (org.onosproject.net.Device)1 Group (org.onosproject.net.group.Group)1 GroupBucket (org.onosproject.net.group.GroupBucket)1 GroupDescription (org.onosproject.net.group.GroupDescription)1 PiFlowRuleTranslatorImpl.translateTreatment (org.onosproject.net.pi.impl.PiFlowRuleTranslatorImpl.translateTreatment)1 PiUtils.getInterpreterOrNull (org.onosproject.net.pi.impl.PiUtils.getInterpreterOrNull)1 PiActionProfileId (org.onosproject.net.pi.model.PiActionProfileId)1 PiActionProfileModel (org.onosproject.net.pi.model.PiActionProfileModel)1 PiPipeconf (org.onosproject.net.pi.model.PiPipeconf)1 PiPipelineInterpreter (org.onosproject.net.pi.model.PiPipelineInterpreter)1 PiAction (org.onosproject.net.pi.runtime.PiAction)1 PiActionProfileGroup (org.onosproject.net.pi.runtime.PiActionProfileGroup)1 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)1 PiActionProfileMember (org.onosproject.net.pi.runtime.PiActionProfileMember)1 PiActionProfileMemberId (org.onosproject.net.pi.runtime.PiActionProfileMemberId)1 PiGroupKey (org.onosproject.net.pi.runtime.PiGroupKey)1