Search in sources :

Example 1 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class OnReceivedDeleteResponseAction method handleResponse.

@Override
protected void handleResponse(FlowCreateFsm stateMachine, SpeakerFlowSegmentResponse response) {
    if (response.isSuccess()) {
        stateMachine.saveActionToHistory("Rule was deleted", format("The rule was deleted: switch %s, cookie %s", response.getSwitchId(), response.getCookie()));
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        stateMachine.getFailedCommands().add(errorResponse.getCommandId());
        stateMachine.saveErrorToHistory("Failed to delete rule", format("Failed to delete the rule: commandId %s, switch %s. Error: %s", errorResponse.getCommandId(), errorResponse.getSwitchId(), errorResponse));
    }
}
Also used : FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse)

Example 2 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class OnReceivedInstallResponseAction method handleError.

private void handleError(FlowCreateFsm stateMachine, SpeakerFlowSegmentResponse response) {
    FlowErrorResponse errorResponse = (FlowErrorResponse) response;
    stateMachine.getFailedCommands().add(response.getCommandId());
    stateMachine.saveErrorToHistory("Failed to install rule", format("Failed to install the rule: switch %s, cookie %s. Error: %s", errorResponse.getSwitchId(), response.getCookie(), errorResponse));
}
Also used : FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse)

Example 3 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class OnReceivedCommandResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    UUID commandId = response.getCommandId();
    FlowSegmentRequestFactory command = stateMachine.getCommands().get(commandId);
    if (!stateMachine.getPendingCommands().containsKey(commandId) || command == null) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.getPendingCommands().remove(commandId);
        stateMachine.saveActionToHistory("Group id was removed", format("The group id was removed: switch %s, cookie %s", response.getSwitchId(), command.getCookie()));
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        int retries = stateMachine.getRetriedCommands().getOrDefault(commandId, 0);
        if (retries < speakerCommandRetriesLimit) {
            stateMachine.getRetriedCommands().put(commandId, ++retries);
            stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_GROUP_ACTION, format("Failed to remove the group: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse, retries));
            stateMachine.getCarrier().sendSpeakerRequest(command.makeInstallRequest(commandId));
        } else {
            stateMachine.getPendingCommands().remove(commandId);
            stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_GROUP_ACTION, format("Failed to remove the group: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.getFailedCommands().put(commandId, errorResponse);
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending remove commands of the flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.GROUP_REMOVED);
        } else {
            String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UUID(java.util.UUID)

Example 4 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class ValidateIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    UUID commandId = response.getCommandId();
    FlowSegmentRequestFactory command = stateMachine.getIngressCommands().get(commandId);
    if (!stateMachine.getPendingCommands().containsKey(commandId) || command == null) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was validated", format("The ingress rule has been validated successfully: switch %s, cookie %s", command.getSwitchId(), command.getCookie()));
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit && errorResponse.getErrorCode() != FlowErrorResponse.ErrorCode.MISSING_OF_FLOWS) {
            stateMachine.saveErrorToHistory(RULE_VALIDATION_FAILED_ACTION, format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse, attempt));
            stateMachine.getCarrier().sendSpeakerRequest(command.makeInstallRequest(commandId));
        } else if (stateMachine.isDoNotRevert()) {
            stateMachine.removePendingCommand(commandId);
            stateMachine.saveErrorToHistory(RULE_VALIDATION_FAILED_ACTION, format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s. " + "Skipping validation attempts", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.setNewFlowStatus(FlowStatus.DOWN);
            stateMachine.setErrorReason(RULE_VALIDATION_FAILED_ACTION);
        } else {
            stateMachine.removePendingCommand(commandId);
            stateMachine.saveErrorToHistory(RULE_VALIDATION_FAILED_ACTION, format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.getFailedValidationResponses().put(commandId, response);
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedValidationResponses().isEmpty()) {
            log.debug("Ingress rules have been validated for flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.RULES_VALIDATED);
        } else {
            stateMachine.saveErrorToHistory(format("Found missing rules or received error response(s) on %d validation commands", stateMachine.getFailedValidationResponses().size()));
            stateMachine.fire(Event.MISSING_RULE_FOUND);
        }
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UUID(java.util.UUID)

Example 5 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class ValidateIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    UUID commandId = response.getCommandId();
    FlowSegmentRequestFactory command = stateMachine.getIngressCommands().get(commandId);
    if (!stateMachine.getPendingCommands().containsKey(commandId) || command == null) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    MeterRegistryHolder.getRegistry().ifPresent(registry -> {
        if (response.getRequestCreateTime() > 0) {
            long roundtrip = Duration.between(Instant.ofEpochMilli(response.getRequestCreateTime()), Instant.now()).toNanos();
            if (roundtrip > 0) {
                registry.timer("fsm.validate_command.roundtrip").record(roundtrip, TimeUnit.NANOSECONDS);
            }
        }
        if (response.getExecutionTime() > 0) {
            registry.timer("fsm.validate_command.floodlight_execution").record(response.getExecutionTime(), TimeUnit.NANOSECONDS);
        }
    });
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was validated", format("The ingress rule has been validated successfully: switch %s, cookie %s", command.getSwitchId(), command.getCookie()));
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit && errorResponse.getErrorCode() == FlowErrorResponse.ErrorCode.MISSING_OF_FLOWS) {
            stateMachine.saveErrorToHistory("Rule validation failed", format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse, attempt));
            stateMachine.getCarrier().sendSpeakerRequest(command.makeVerifyRequest(commandId));
        } else {
            stateMachine.removePendingCommand(commandId);
            stateMachine.saveErrorToHistory("Rule validation failed", format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.getFailedValidationResponses().put(commandId, response);
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedValidationResponses().isEmpty()) {
            log.debug("Ingress rules have been validated for flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.RULES_VALIDATED);
        } else {
            stateMachine.saveErrorToHistory(format("Found missing rules or received error response(s) on %d validation commands", stateMachine.getFailedValidationResponses().size()));
            stateMachine.fire(Event.MISSING_RULE_FOUND);
        }
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UUID(java.util.UUID)

Aggregations

FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)25 UUID (java.util.UUID)16 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)15 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)15 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)3 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)3 String.format (java.lang.String.format)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)2 FlowPathSwapContext (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapContext)2 FlowPathSwapFsm (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm)2 Event (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm.Event)2 State (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm.State)2 SessionErrorResponseException (org.openkilda.floodlight.error.SessionErrorResponseException)1 SwitchMissingFlowsException (org.openkilda.floodlight.error.SwitchMissingFlowsException)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 ErrorCode (org.openkilda.floodlight.flow.response.FlowErrorResponse.ErrorCode)1 FlowErrorResponseBuilder (org.openkilda.floodlight.flow.response.FlowErrorResponse.FlowErrorResponseBuilder)1