Java Code Examples for org.onosproject.net.pi.model.PiPipelineInterpreter#PiInterpreterException

The following examples show how to use org.onosproject.net.pi.model.PiPipelineInterpreter#PiInterpreterException . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: P4RuntimePacketProgrammable.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void emit(OutboundPacket packet) {

    if (!this.setupBehaviour("emit()")) {
        return;
    }

    final PiPipelineInterpreter interpreter = getInterpreter(handler());
    if (interpreter == null) {
        // Error logged by getInterpreter().
        return;
    }

    if (log.isTraceEnabled()) {
        logPacketOut(packet);
    }

    try {
        interpreter.mapOutboundPacket(packet).forEach(
                op -> client.packetOut(p4DeviceId, op, pipeconf));
    } catch (PiPipelineInterpreter.PiInterpreterException e) {
        log.error("Unable to translate outbound packet for {} with pipeconf {}: {}",
                  deviceId, pipeconf.id(), e.getMessage());
    }
}
 
Example 2
Source File: AbstractObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
TrafficTreatment mapTreatmentToPiIfNeeded(TrafficTreatment treatment, PiTableId tableId)
        throws FabricPipelinerException {
    if (isTreatmentPi(treatment)) {
        return treatment;
    }
    final PiAction piAction;
    try {
        piAction = interpreter.mapTreatment(treatment, tableId);
    } catch (PiPipelineInterpreter.PiInterpreterException ex) {
        throw new FabricPipelinerException(
                format("Unable to map treatment for table '%s': %s",
                       tableId, ex.getMessage()),
                ObjectiveError.UNSUPPORTED);
    }
    return DefaultTrafficTreatment.builder()
            .piTableAction(piAction)
            .build();
}
 
Example 3
Source File: PiFlowRuleTranslatorImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a PI action out of the given treatment, optionally using the given
 * interpreter.
 */
private static PiTableAction buildAction(TrafficTreatment treatment, PiPipelineInterpreter interpreter,
                                         PiTableId tableId)
        throws PiTranslationException {

    PiTableAction piTableAction = null;

    // If treatment has only one instruction of type PiInstruction, use that.
    for (Instruction inst : treatment.allInstructions()) {
        if (inst.type() == Instruction.Type.PROTOCOL_INDEPENDENT) {
            if (treatment.allInstructions().size() == 1) {
                piTableAction = ((PiInstruction) inst).action();
            } else {
                throw new PiTranslationException(format(
                        "Unable to translate treatment, found multiple instructions " +
                                "of which one is protocol-independent: %s", treatment));
            }
        }
    }

    if (piTableAction == null && interpreter != null) {
        // No PiInstruction, use interpreter to build action.
        try {
            piTableAction = interpreter.mapTreatment(treatment, tableId);
        } catch (PiPipelineInterpreter.PiInterpreterException e) {
            throw new PiTranslationException(
                    "Interpreter was unable to translate treatment. " + e.getMessage());
        }
    }

    return piTableAction;
}