Search in sources :

Example 1 with SessionErrorResponseException

use of org.openkilda.floodlight.error.SessionErrorResponseException in project open-kilda by telstra.

the class FlowSegmentReport method assembleResponse.

private SpeakerResponse assembleResponse() {
    FlowErrorResponseBuilder errorResponse = makeErrorTemplate();
    try {
        raiseError();
        return makeSuccessReply();
    } catch (SwitchNotFoundException e) {
        errorResponse.errorCode(ErrorCode.SWITCH_UNAVAILABLE);
    } catch (SessionErrorResponseException e) {
        decodeError(errorResponse, e.getErrorResponse());
    } catch (SwitchMissingFlowsException e) {
        errorResponse.errorCode(ErrorCode.MISSING_OF_FLOWS);
        errorResponse.description(e.getMessage());
    } catch (SwitchOperationException e) {
        errorResponse.errorCode(ErrorCode.UNKNOWN);
        errorResponse.description(e.getMessage());
    } catch (Exception e) {
        log.error(String.format("Unhandled exception while processing command %s", command), e);
        errorResponse.errorCode(ErrorCode.UNKNOWN);
    }
    FlowErrorResponse response = errorResponse.build();
    log.error("Command {} have failed - {} {}", command, response.getErrorCode(), response.getDescription());
    return response;
}
Also used : SwitchMissingFlowsException(org.openkilda.floodlight.error.SwitchMissingFlowsException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowErrorResponseBuilder(org.openkilda.floodlight.flow.response.FlowErrorResponse.FlowErrorResponseBuilder) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SwitchMissingFlowsException(org.openkilda.floodlight.error.SwitchMissingFlowsException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException)

Example 2 with SessionErrorResponseException

use of org.openkilda.floodlight.error.SessionErrorResponseException in project open-kilda by telstra.

the class SpeakerCommand method setupErrorHandler.

protected CompletableFuture<Optional<OFMessage>> setupErrorHandler(CompletableFuture<Optional<OFMessage>> future, IOfErrorResponseHandler handler) {
    CompletableFuture<Optional<OFMessage>> branch = new CompletableFuture<>();
    future.whenComplete((response, error) -> {
        if (error == null) {
            branch.complete(response);
        } else {
            Throwable actualError = unwrapError(error);
            if (actualError instanceof SessionErrorResponseException) {
                OFErrorMsg errorResponse = ((SessionErrorResponseException) error).getErrorResponse();
                propagateFutureResponse(branch, handler.handleOfError(errorResponse));
            } else {
                branch.completeExceptionally(actualError);
            }
        }
    });
    return branch;
}
Also used : OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException)

Example 3 with SessionErrorResponseException

use of org.openkilda.floodlight.error.SessionErrorResponseException in project open-kilda by telstra.

the class MeterInstallCommandTest method notConflictError.

@Test
public void notConflictError() throws Throwable {
    switchFeaturesSetup(sw, true);
    replayAll();
    CompletableFuture<MeterInstallReport> result = command.execute(commandProcessor);
    SessionWriteRecord write0 = getWriteRecord(0);
    OFErrorMsg error = sw.getOFFactory().errorMsgs().buildBadRequestErrorMsg().setCode(OFBadRequestCode.BAD_LEN).build();
    write0.getFuture().completeExceptionally(new SessionErrorResponseException(sw.getId(), error));
    verifyErrorCompletion(result, SwitchErrorResponseException.class);
}
Also used : OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) Test(org.junit.Test) AbstractSpeakerCommandTest(org.openkilda.floodlight.command.AbstractSpeakerCommandTest)

Example 4 with SessionErrorResponseException

use of org.openkilda.floodlight.error.SessionErrorResponseException in project open-kilda by telstra.

the class MeterInstallCommandTest method processConflictError.

private CompletableFuture<MeterInstallReport> processConflictError() {
    CompletableFuture<MeterInstallReport> result = command.execute(commandProcessor);
    SessionWriteRecord write0 = getWriteRecord(0);
    OFErrorMsg error = sw.getOFFactory().errorMsgs().buildMeterModFailedErrorMsg().setCode(OFMeterModFailedCode.METER_EXISTS).build();
    write0.getFuture().completeExceptionally(new SessionErrorResponseException(sw.getId(), error));
    return result;
}
Also used : OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException)

Example 5 with SessionErrorResponseException

use of org.openkilda.floodlight.error.SessionErrorResponseException in project open-kilda by telstra.

the class Session method handleResponse.

/**
 * Handle switch response.
 *
 * <p>Lookup sent request by message Xid and mark it as completed(errored) if found. Return "true" if the
 * session is completed and can be wiped, return "false" if the session need more responses.
 */
boolean handleResponse(OFMessage message) {
    CompletableFuture<Optional<OFMessage>> future;
    future = requestsByXid.get(message.getXid());
    if (future == null) {
        throw new IllegalArgumentException(String.format("%s must never route \"foreign\" response", group.getClass().getName()));
    }
    if (future.isDone()) {
        // it can already be marked as failed by results of some session wide errors
        return false;
    }
    // Setup correlationId (because this method called asynchronously by FL core).
    try (CorrelationContext.CorrelationContextClosable closable = CorrelationContext.create(context.getCorrelationId())) {
        if (OFType.ERROR == message.getType()) {
            future.completeExceptionally(new SessionErrorResponseException(sw.getId(), (OFErrorMsg) message));
        } else {
            future.complete(Optional.of(message));
        }
        // check session completion (we have received all responses, if we got response for closing barrier request)
        if (closingBarrier != null && closingBarrier.isDone()) {
            incompleteRequestsStream().forEach(entry -> entry.complete(Optional.empty()));
            return true;
        }
        return false;
    }
}
Also used : OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) Optional(java.util.Optional) CorrelationContext(org.openkilda.floodlight.utils.CorrelationContext) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException)

Aggregations

SessionErrorResponseException (org.openkilda.floodlight.error.SessionErrorResponseException)5 OFErrorMsg (org.projectfloodlight.openflow.protocol.OFErrorMsg)4 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.Test)1 AbstractSpeakerCommandTest (org.openkilda.floodlight.command.AbstractSpeakerCommandTest)1 SwitchMissingFlowsException (org.openkilda.floodlight.error.SwitchMissingFlowsException)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)1 FlowErrorResponseBuilder (org.openkilda.floodlight.flow.response.FlowErrorResponse.FlowErrorResponseBuilder)1 CorrelationContext (org.openkilda.floodlight.utils.CorrelationContext)1