use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class OnErrorResponseAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
if (response.isSuccess() || !(response instanceof FlowErrorResponse)) {
throw new IllegalArgumentException(format("Invoked %s for a success response: %s", this.getClass(), response));
}
UUID failedCommandId = response.getCommandId();
FlowSegmentRequestFactory failedCommand = stateMachine.getRemoveCommands().get(failedCommandId);
if (!stateMachine.getPendingCommands().contains(failedCommandId) || failedCommand == null) {
log.info("Received a response for unexpected command: {}", response);
return;
}
FlowErrorResponse errorResponse = (FlowErrorResponse) response;
int attempt = stateMachine.doRetryForCommand(failedCommandId);
if (attempt <= speakerCommandRetriesLimit) {
stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s. Retrying (attempt %d)", failedCommandId, errorResponse.getSwitchId(), response.getCookie(), errorResponse, attempt));
stateMachine.getCarrier().sendSpeakerRequest(failedCommand.makeRemoveRequest(failedCommandId));
} else {
stateMachine.removePendingCommand(failedCommandId);
stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s", failedCommandId, errorResponse.getSwitchId(), response.getCookie(), errorResponse));
stateMachine.addFailedCommand(failedCommandId, errorResponse);
if (stateMachine.getPendingCommands().isEmpty()) {
String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fire(Event.RULES_REMOVED);
}
}
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class FlowRerouteService method handleAsyncResponse.
/**
* Handles async response from worker.
*
* @param key command identifier.
*/
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerFlowSegmentResponse flowResponse) throws UnknownKeyException {
log.debug("Received flow command response {}", flowResponse);
FlowRerouteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
FlowRerouteContext context = FlowRerouteContext.builder().speakerFlowResponse(flowResponse).build();
if (flowResponse instanceof FlowErrorResponse) {
fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
} else {
fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
}
removeIfFinished(fsm, key);
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class ValidateNonIngressRulesAction 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.getNonIngressCommands().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 non 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 non 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 if (stateMachine.isDoNotRevert()) {
stateMachine.removePendingCommand(commandId);
stateMachine.saveErrorToHistory(RULE_VALIDATION_FAILED_ACTION, format("Failed to validate non 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 non 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("Non 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);
}
}
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class ValidateNonIngressRulesAction 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.getNonIngressCommands().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 non 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 non 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 non 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("Non 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);
}
}
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class OnReceivedRemoveOrRevertResponseAction 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 removeCommand = stateMachine.getRemoveCommands().get(commandId);
FlowSegmentRequestFactory installCommand = stateMachine.getInstallCommand(commandId);
if (!stateMachine.getPendingCommands().containsKey(commandId) || (removeCommand == null && installCommand == null)) {
log.info("Received a response for unexpected command: {}", response);
return;
}
if (response.isSuccess()) {
stateMachine.removePendingCommand(commandId);
if (removeCommand != null) {
stateMachine.saveActionToHistory("Rule was deleted", format("The rule was removed: switch %s, cookie %s", response.getSwitchId(), removeCommand.getCookie()));
} else {
stateMachine.saveActionToHistory("Rule was re-installed (reverted)", format("The rule was installed: switch %s, cookie %s", response.getSwitchId(), installCommand.getCookie()));
}
} else {
FlowErrorResponse errorResponse = (FlowErrorResponse) response;
int attempt = stateMachine.doRetryForCommand(commandId);
if (attempt <= speakerCommandRetriesLimit) {
if (removeCommand != null) {
stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse, attempt));
stateMachine.getCarrier().sendSpeakerRequest(removeCommand.makeRemoveRequest(commandId));
} else {
stateMachine.saveErrorToHistory("Failed to re-install (revert) rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse, attempt));
stateMachine.getCarrier().sendSpeakerRequest(installCommand.makeInstallRequest(commandId));
}
} else {
stateMachine.removePendingCommand(commandId);
if (removeCommand != null) {
stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse));
} else {
stateMachine.saveErrorToHistory("Failed to re-install rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse));
}
stateMachine.addFailedCommand(commandId, errorResponse);
}
}
if (stateMachine.getPendingCommands().isEmpty()) {
if (stateMachine.getFailedCommands().isEmpty()) {
log.debug("Received responses for all pending remove / re-install commands of the flow {}", stateMachine.getFlowId());
stateMachine.fire(Event.RULES_REMOVED);
} else {
String errorMessage = format("Received error response(s) for %d remove / re-install commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fireError(errorMessage);
}
}
}
Aggregations