Search in sources :

Example 1 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam 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 2 with PiActionParam

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

the class PiGroupTranslatorImplTest method selectOutputBucket.

private static GroupBucket selectOutputBucket(int portNum) {
    ImmutableByteSequence paramVal = copyFrom(portNum);
    PiActionParam param = new PiActionParam(PORT, paramVal);
    PiTableAction action = PiAction.builder().withId(INGRESS_WCMP_CONTROL_SET_EGRESS_PORT).withParameter(param).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().add(Instructions.piTableAction(action)).build();
    return DefaultGroupBucket.createSelectGroupBucket(treatment);
}
Also used : PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 3 with PiActionParam

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

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

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

the class IntProgrammableImpl method buildWatchlistEntry.

private FlowRule buildWatchlistEntry(IntObjective obj) {
    int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
    PiActionParam hopMetaLenParam = new PiActionParam(IntConstants.HOP_METADATA_LEN, ImmutableByteSequence.copyFrom(Integer.bitCount(instructionBitmap)));
    PiActionParam hopCntParam = new PiActionParam(IntConstants.REMAINING_HOP_CNT, ImmutableByteSequence.copyFrom(MAXHOP));
    PiActionParam inst0003Param = new PiActionParam(IntConstants.INS_MASK0003, ImmutableByteSequence.copyFrom((instructionBitmap >> 12) & 0xF));
    PiActionParam inst0407Param = new PiActionParam(IntConstants.INS_MASK0407, ImmutableByteSequence.copyFrom((instructionBitmap >> 8) & 0xF));
    PiAction intSourceAction = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_INT_SOURCE_DSCP).withParameter(hopMetaLenParam).withParameter(hopCntParam).withParameter(inst0003Param).withParameter(inst0407Param).build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder().piTableAction(intSourceAction).build();
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    for (Criterion criterion : obj.selector().criteria()) {
        switch(criterion.type()) {
            case IPV4_SRC:
                sBuilder.matchIPSrc(((IPCriterion) criterion).ip());
                break;
            case IPV4_DST:
                sBuilder.matchIPDst(((IPCriterion) criterion).ip());
                break;
            case TCP_SRC:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_SRC_PORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
                break;
            case UDP_SRC:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_SRC_PORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
                break;
            case TCP_DST:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_DST_PORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
                break;
            case UDP_DST:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_DST_PORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
                break;
            default:
                log.warn("Unsupported criterion type: {}", criterion.type());
        }
    }
    return DefaultFlowRule.builder().forDevice(this.data().deviceId()).withSelector(sBuilder.build()).withTreatment(instTreatment).withPriority(DEFAULT_PRIORITY).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_TB_INT_SOURCE).fromApp(appId).withIdleTimeout(IDLE_TIMEOUT).build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) 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)

Aggregations

PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)52 PiAction (org.onosproject.net.pi.runtime.PiAction)45 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)32 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)32 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 Test (org.junit.Test)21 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)11 FlowRule (org.onosproject.net.flow.FlowRule)11 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)11 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)7 GroupDescription (org.onosproject.net.group.GroupDescription)6 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)5 NextObjective (org.onosproject.net.flowobjective.NextObjective)5 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)5 PortNumber (org.onosproject.net.PortNumber)4 PiInstruction (org.onosproject.net.flow.instructions.PiInstruction)4 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)4 GroupBucket (org.onosproject.net.group.GroupBucket)4 GroupBuckets (org.onosproject.net.group.GroupBuckets)4