use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class ActionCodec method encode.
@Override
protected P4RuntimeOuterClass.Action encode(PiAction piAction, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException, P4InfoBrowser.NotFoundException {
final int actionId = browser.actions().getByName(piAction.id().toString()).getPreamble().getId();
final P4RuntimeOuterClass.Action.Builder actionMsgBuilder = P4RuntimeOuterClass.Action.newBuilder().setActionId(actionId);
for (PiActionParam p : piAction.parameters()) {
final P4InfoOuterClass.Action.Param paramInfo = browser.actionParams(actionId).getByName(p.id().toString());
final ByteString paramValue;
if (browser.isTypeString(paramInfo.getTypeName())) {
paramValue = ByteString.copyFrom(p.value().asReadOnlyBuffer());
} else {
paramValue = ByteString.copyFrom(p.value().canonical().asReadOnlyBuffer());
// Check size only if the param type is not a sdn_string
assertSize(format("param '%s' of action '%s'", p.id(), piAction.id()), paramValue, paramInfo.getBitwidth());
}
actionMsgBuilder.addParams(P4RuntimeOuterClass.Action.Param.newBuilder().setParamId(paramInfo.getId()).setValue(paramValue).build());
}
return actionMsgBuilder.build();
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class FabricIntProgrammable method setSourcePort.
@Override
public boolean setSourcePort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
PiCriterion ingressCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_IG_PORT, port.toLong()).build();
TrafficSelector srcSelector = DefaultTrafficSelector.builder().matchPi(ingressCriterion).build();
PiAction setSourceAct = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE).build();
TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder().piTableAction(setSourceAct).build();
FlowRule srcFlowRule = DefaultFlowRule.builder().withSelector(srcSelector).withTreatment(srcTreatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE).build();
flowRuleService.applyFlowRules(srcFlowRule);
return true;
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class FabricIntProgrammable method init.
@Override
public boolean init() {
if (!setupBehaviour()) {
return false;
}
// FIXME: create config class for INT to allow specifying arbitrary
// switch IDs. The one for the GeneralDeviceProvider was temporary and
// now has been removed. For now we use the chassis ID.
// final GeneralProviderDeviceConfig cfg = cfgService.getConfig(
// deviceId, GeneralProviderDeviceConfig.class);
// if (cfg == null) {
// log.warn("Missing GeneralProviderDevice config for {}", deviceId);
// return false;
// }
// final String switchId = cfg.protocolsInfo().containsKey("int") ?
// cfg.protocolsInfo().get("int").configValues().get("switchId")
// : null;
// if (switchId == null || switchId.isEmpty()) {
// log.warn("Missing INT device config for {}", deviceId);
// return false;
// }
PiActionParam transitIdParam = new PiActionParam(FabricConstants.SWITCH_ID, copyFrom(handler().get(DeviceService.class).getDevice(deviceId).chassisId().id()));
PiAction transitAction = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INIT_METADATA).withParameter(transitIdParam).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(transitAction).build();
TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_INT_IS_VALID, (byte) 0x01).build()).build();
FlowRule transitFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT).build();
flowRuleService.applyFlowRules(transitFlowRule);
return true;
}
use of org.onosproject.net.pi.runtime.PiAction 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();
}
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);
}
Aggregations