Search in sources :

Example 1 with PiAction

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

Example 2 with PiAction

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

the class PiFlowRuleTranslatorImpl method checkPiAction.

private static PiTableAction checkPiAction(PiAction piAction, PiTableModel table) throws PiTranslationException {
    // Table supports this action?
    PiActionModel actionModel = table.action(piAction.id()).orElseThrow(() -> new PiTranslationException(format("Not such action '%s' for table '%s'", piAction.id(), table.id())));
    // Is the number of runtime parameters correct?
    if (actionModel.params().size() != piAction.parameters().size()) {
        throw new PiTranslationException(format("Wrong number of runtime parameters for action '%s', expected %d but found %d", actionModel.id(), actionModel.params().size(), piAction.parameters().size()));
    }
    // Forge a new action instance with well-sized parameters.
    // The same comment as in typeCheckFieldMatch() about duplicating field match instances applies here.
    PiAction.Builder newActionBuilder = PiAction.builder().withId(piAction.id());
    for (PiActionParam param : piAction.parameters()) {
        PiActionParamModel paramModel = actionModel.param(param.id()).orElseThrow(() -> new PiTranslationException(format("Not such parameter '%s' for action '%s'", param.id(), actionModel)));
        try {
            newActionBuilder.withParameter(new PiActionParam(param.id(), paramModel.hasBitWidth() ? param.value().fit(paramModel.bitWidth()) : param.value()));
        } catch (ByteSequenceTrimException e) {
            throw new PiTranslationException(format("Size mismatch for parameter '%s' of action '%s': %s", param.id(), piAction.id(), e.getMessage()));
        }
    }
    return newActionBuilder.build();
}
Also used : PiActionModel(org.onosproject.net.pi.model.PiActionModel) PiActionParamModel(org.onosproject.net.pi.model.PiActionParamModel) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) ByteSequenceTrimException(org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 3 with PiAction

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

the class PiGroupTranslatorImplTest method outputMember.

private static PiActionProfileMember outputMember(int portNum) throws ImmutableByteSequence.ByteSequenceTrimException {
    PiActionParam param = new PiActionParam(PORT, copyFrom(portNum).fit(PORT_BITWIDTH));
    PiAction piAction = PiAction.builder().withId(INGRESS_WCMP_CONTROL_SET_EGRESS_PORT).withParameter(param).build();
    return PiActionProfileMember.builder().forActionProfile(INGRESS_WCMP_CONTROL_WCMP_SELECTOR).withAction(piAction).withId(PiActionProfileMemberId.of(BASE_MEM_ID + portNum)).build();
}
Also used : PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 4 with PiAction

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

the class IntProgrammableImpl method buildReportEntry.

private FlowRule buildReportEntry(IntDeviceConfig cfg) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(IntConstants.HDR_INT_IS_VALID, (byte) 0x01).build()).build();
    PiActionParam srcMacParam = new PiActionParam(IntConstants.SRC_MAC, ImmutableByteSequence.copyFrom(cfg.sinkMac().toBytes()));
    PiActionParam nextHopMacParam = new PiActionParam(IntConstants.MON_MAC, ImmutableByteSequence.copyFrom(cfg.collectorNextHopMac().toBytes()));
    PiActionParam srcIpParam = new PiActionParam(IntConstants.SRC_IP, ImmutableByteSequence.copyFrom(cfg.sinkIp().toOctets()));
    PiActionParam monIpParam = new PiActionParam(IntConstants.MON_IP, ImmutableByteSequence.copyFrom(cfg.collectorIp().toOctets()));
    PiActionParam monPortParam = new PiActionParam(IntConstants.MON_PORT, ImmutableByteSequence.copyFrom(cfg.collectorPort().toInt()));
    PiAction reportAction = PiAction.builder().withId(IntConstants.EGRESS_PROCESS_INT_REPORT_DO_REPORT_ENCAPSULATION).withParameter(srcMacParam).withParameter(nextHopMacParam).withParameter(srcIpParam).withParameter(monIpParam).withParameter(monPortParam).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(reportAction).build();
    return DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(this.data().deviceId()).forTable(IntConstants.EGRESS_PROCESS_INT_REPORT_TB_GENERATE_REPORT).build();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 5 with PiAction

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

the class IntProgrammableImpl method populateInstTableEntry.

private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId, int matchValue, PiActionId actionId, ApplicationId appId) {
    PiCriterion instCriterion = PiCriterion.builder().matchExact(matchFieldId, matchValue).build();
    TrafficSelector instSelector = DefaultTrafficSelector.builder().matchPi(instCriterion).build();
    PiAction instAction = PiAction.builder().withId(actionId).build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder().piTableAction(instAction).build();
    FlowRule instFlowRule = DefaultFlowRule.builder().withSelector(instSelector).withTreatment(instTreatment).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(tableId).fromApp(appId).build();
    flowRuleService.applyFlowRules(instFlowRule);
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiAction (org.onosproject.net.pi.runtime.PiAction)57 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)39 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)39 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)31 TrafficSelector (org.onosproject.net.flow.TrafficSelector)31 Test (org.junit.Test)25 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)19 FlowRule (org.onosproject.net.flow.FlowRule)19 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)17 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 GroupDescription (org.onosproject.net.group.GroupDescription)10 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)6 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)6 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)5 NextObjective (org.onosproject.net.flowobjective.NextObjective)5 GroupBucket (org.onosproject.net.group.GroupBucket)5 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)5