Search in sources :

Example 11 with PiAction

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();
}
Also used : PiAction(org.onosproject.net.pi.runtime.PiAction) ByteString(com.google.protobuf.ByteString) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam)

Example 12 with PiAction

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

Example 13 with PiAction

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;
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) 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 14 with PiAction

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

Example 15 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)117 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)74 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)69 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)68 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)57 Test (org.junit.Test)44 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)44 FlowRule (org.onosproject.net.flow.FlowRule)39 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)33 GroupDescription (org.onosproject.net.group.GroupDescription)22 List (java.util.List)15 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)14 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)14 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)13 PortNumber (org.onosproject.net.PortNumber)9 NextObjective (org.onosproject.net.flowobjective.NextObjective)9 GroupBucket (org.onosproject.net.group.GroupBucket)9 PiActionId (org.onosproject.net.pi.model.PiActionId)9 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)9