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();
}
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);
}
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();
}
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();
}
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();
}
Aggregations