Search in sources :

Example 11 with PiTranslationException

use of org.onosproject.net.pi.service.PiTranslationException in project onos by opennetworkinglab.

the class P4RuntimeFlowRuleProgrammable method processFlowRules.

private Collection<FlowRule> processFlowRules(Collection<FlowRule> rules, Operation driverOperation) {
    if (!setupBehaviour("processFlowRules()") || rules.isEmpty()) {
        return Collections.emptyList();
    }
    // Created batched write request.
    final WriteRequest request = client.write(p4DeviceId, pipeconf);
    // For each rule, translate to PI and append to write request.
    final Map<PiHandle, FlowRule> handleToRuleMap = Maps.newHashMap();
    final List<FlowRule> skippedRules = Lists.newArrayList();
    final CompletableFuture<WriteResponse> futureResponse;
    WRITE_LOCKS.get(deviceId).lock();
    try {
        for (FlowRule rule : rules) {
            // Translate.
            final PiTableEntry entry;
            try {
                entry = translator.translate(rule, pipeconf);
            } catch (PiTranslationException e) {
                log.warn("Unable to translate flow rule for pipeconf '{}': {} [{}]", pipeconf.id(), e.getMessage(), rule);
                // Next rule.
                continue;
            }
            final PiTableEntryHandle handle = entry.handle(deviceId);
            handleToRuleMap.put(handle, rule);
            // Update translation store.
            if (driverOperation.equals(APPLY)) {
                translator.learn(handle, new PiTranslatedEntity<>(rule, entry, handle));
            } else {
                translator.forget(handle);
            }
            // Append entry to batched write request (returns false), or skip (true)
            if (appendEntryToWriteRequestOrSkip(request, handle, entry, driverOperation)) {
                skippedRules.add(rule);
            }
        }
        if (request.pendingUpdates().isEmpty()) {
            // All good. No need to write on device.
            return rules;
        }
        // Update mirror.
        tableMirror.applyWriteRequest(request);
        // Async submit request to server.
        futureResponse = request.submit();
    } finally {
        WRITE_LOCKS.get(deviceId).unlock();
    }
    // Wait for response.
    final WriteResponse response = Futures.getUnchecked(futureResponse);
    // Derive successfully applied flow rule from response.
    final List<FlowRule> appliedRules = getAppliedFlowRules(response, handleToRuleMap, driverOperation);
    // Return skipped and applied rules.
    return ImmutableList.<FlowRule>builder().addAll(skippedRules).addAll(appliedRules).build();
}
Also used : PiHandle(org.onosproject.net.pi.runtime.PiHandle) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) WriteResponse(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteResponse) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) FlowRule(org.onosproject.net.flow.FlowRule) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiTableEntryHandle(org.onosproject.net.pi.runtime.PiTableEntryHandle)

Example 12 with PiTranslationException

use of org.onosproject.net.pi.service.PiTranslationException in project onos by opennetworkinglab.

the class P4RuntimeMeterProgrammable method processMeterOp.

private boolean processMeterOp(MeterOperation meterOp) {
    PiMeterCellConfig piMeterCellConfig;
    final PiMeterCellHandle handle = PiMeterCellHandle.of(deviceId, (PiMeterCellId) meterOp.meter().meterCellId());
    boolean result = true;
    WRITE_LOCKS.get(deviceId).lock();
    try {
        switch(meterOp.type()) {
            case ADD:
            case MODIFY:
                // Create a config for modify operation
                try {
                    piMeterCellConfig = translator.translate(meterOp.meter(), pipeconf);
                } catch (PiTranslationException e) {
                    log.warn("Unable translate meter, aborting meter operation {}: {}", meterOp.type(), e.getMessage());
                    log.debug("exception", e);
                    return false;
                }
                translator.learn(handle, new PiTranslatedEntity<>(meterOp.meter(), piMeterCellConfig, handle));
                break;
            case REMOVE:
                // Create a empty config for reset operation
                PiMeterCellId piMeterCellId = (PiMeterCellId) meterOp.meter().meterCellId();
                piMeterCellConfig = PiMeterCellConfig.reset(piMeterCellId);
                translator.forget(handle);
                break;
            default:
                log.warn("Meter Operation type {} not supported", meterOp.type());
                return false;
        }
        WriteRequest request = client.write(p4DeviceId, pipeconf).entity(piMeterCellConfig, UpdateType.MODIFY);
        if (!request.pendingUpdates().isEmpty()) {
            result = request.submitSync().isSuccess();
        }
    } finally {
        WRITE_LOCKS.get(deviceId).unlock();
    }
    return result;
}
Also used : PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) PiMeterCellConfig(org.onosproject.net.pi.runtime.PiMeterCellConfig) WriteRequest(org.onosproject.p4runtime.api.P4RuntimeWriteClient.WriteRequest) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiMeterCellHandle(org.onosproject.net.pi.runtime.PiMeterCellHandle)

Aggregations

PiTranslationException (org.onosproject.net.pi.service.PiTranslationException)12 ByteSequenceTrimException (org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException)5 ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)4 PiExactFieldMatch (org.onosproject.net.pi.runtime.PiExactFieldMatch)4 PiLpmFieldMatch (org.onosproject.net.pi.runtime.PiLpmFieldMatch)4 PiOptionalFieldMatch (org.onosproject.net.pi.runtime.PiOptionalFieldMatch)4 PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)4 Sets (com.google.common.collect.Sets)3 String.format (java.lang.String.format)3 Set (java.util.Set)3 Device (org.onosproject.net.Device)3 FlowRule (org.onosproject.net.flow.FlowRule)3 PiUtils.getInterpreterOrNull (org.onosproject.net.pi.impl.PiUtils.getInterpreterOrNull)3 PiActionModel (org.onosproject.net.pi.model.PiActionModel)3 PiActionParamModel (org.onosproject.net.pi.model.PiActionParamModel)3 PiPipeconf (org.onosproject.net.pi.model.PiPipeconf)3 PiPipelineInterpreter (org.onosproject.net.pi.model.PiPipelineInterpreter)3 PiAction (org.onosproject.net.pi.runtime.PiAction)3 Maps (com.google.common.collect.Maps)2 Collection (java.util.Collection)2