Search in sources :

Example 1 with SpeakerResponse

use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.

the class YFlowRerouteHubBolt method onWorkerResponse.

@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
    String operationKey = pullKey(input);
    currentKey = KeyProvider.getParentKey(operationKey);
    SpeakerResponse speakerResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerResponse.class);
    try {
        yFlowRerouteService.handleAsyncResponse(currentKey, speakerResponse);
    } catch (UnknownKeyException e) {
        log.error("Received a response with unknown key {}.", currentKey);
    }
}
Also used : SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 2 with SpeakerResponse

use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.

the class YFlowCreateHubBolt method onWorkerResponse.

@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
    String operationKey = pullKey(input);
    currentKey = KeyProvider.getParentKey(operationKey);
    SpeakerResponse speakerResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerResponse.class);
    try {
        yFlowCreateService.handleAsyncResponse(currentKey, speakerResponse);
    } catch (UnknownKeyException e) {
        log.error("Received a response with unknown key {}.", currentKey);
    }
}
Also used : SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 3 with SpeakerResponse

use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.

the class ValidateIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    SpeakerResponse response = context.getSpeakerResponse();
    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", 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 {
            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) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UUID(java.util.UUID)

Example 4 with SpeakerResponse

use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.

the class SetValidateRuleErrorAction method execute.

@Override
public void execute(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Set<SwitchId> switches = Stream.concat(stateMachine.getPendingCommands().values().stream(), stateMachine.getFailedValidationResponses().values().stream().map(SpeakerResponse::getSwitchId)).collect(Collectors.toSet());
    stateMachine.setRerouteError(new SpeakerRequestError("Failed to validate rules", switches));
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingCommands();
}
Also used : SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) SwitchId(org.openkilda.model.SwitchId) SpeakerRequestError(org.openkilda.messaging.info.reroute.error.SpeakerRequestError)

Example 5 with SpeakerResponse

use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.

the class YFlowUpdateServiceTest method processUpdateRequestAndSpeakerCommands.

private void processUpdateRequestAndSpeakerCommands(YFlowPartialUpdateRequest request) throws DuplicateKeyException {
    YFlowUpdateService service = makeYFlowUpdateService(0);
    service.handlePartialUpdateRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS);
    handleSpeakerRequests(speakerRequest -> {
        SpeakerResponse commandResponse;
        if (speakerRequest instanceof FlowSegmentRequest) {
            FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
            commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
        } else {
            BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
            commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
        }
        handleAsyncResponse(service, request.getYFlowId(), commandResponse);
    });
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)

Aggregations

SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)33 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)21 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)21 CommandContext (org.openkilda.wfm.CommandContext)9 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)6 UUID (java.util.UUID)4 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)4 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)3 String.format (java.lang.String.format)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)2 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)2 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)2 SpeakerRequestError (org.openkilda.messaging.info.reroute.error.SpeakerRequestError)2 SwitchId (org.openkilda.model.SwitchId)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