Search in sources :

Example 1 with FlowSegmentRequest

use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.

the class InstallRulesAction method emitInstallRequests.

protected void emitInstallRequests(FlowCreateFsm stateMachine, List<FlowSegmentRequestFactory> factories) {
    Map<UUID, SpeakerCommandObserver> pendingRequests = stateMachine.getPendingCommands();
    List<FlowSegmentRequestFactory> sentCommands = stateMachine.getSentCommands();
    for (FlowSegmentRequestFactory factory : factories) {
        FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
        SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, request);
        commandObserver.start();
        sentCommands.add(factory);
        // TODO ensure no conflicts
        pendingRequests.put(request.getCommandId(), commandObserver);
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerCommandObserver(org.openkilda.wfm.topology.flowhs.service.SpeakerCommandObserver) UUID(java.util.UUID)

Example 2 with FlowSegmentRequest

use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.

the class EmitIngressRulesVerifyRequestsAction method perform.

@Override
public void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getIngressCommands();
    List<FlowSegmentRequestFactory> requestFactories = new ArrayList<>(requestsStorage.values());
    requestsStorage.clear();
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    for (FlowSegmentRequestFactory factory : requestFactories) {
        FlowSegmentRequest request = factory.makeVerifyRequest(commandIdGenerator.generate());
        // TODO ensure no conflicts
        requestsStorage.put(request.getCommandId(), factory);
        stateMachine.getCarrier().sendSpeakerRequest(request);
    }
    requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
    stateMachine.saveActionToHistory("Started validation of installed ingress rules");
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 3 with FlowSegmentRequest

use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.

the class InstallIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(flow);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for commandBuilder.buildIngressOnly() to use proper (updated) encapsulation type.
        flow.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> requestFactories = new ArrayList<>();
    if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
        SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(newForward.getSrcSwitchId(), newReverse.getSrcSwitchId());
        requestFactories.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newForward, newReverse, speakerContext));
    }
    // Installation of ingress rules for protected paths is skipped. These paths are activated on swap.
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    if (requestFactories.isEmpty()) {
        stateMachine.saveActionToHistory("No need to install ingress rules");
        stateMachine.fire(Event.INGRESS_IS_SKIPPED);
    } else {
        Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getIngressCommands();
        for (FlowSegmentRequestFactory factory : requestFactories) {
            FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
            requestsStorage.put(request.getCommandId(), factory);
            stateMachine.getCarrier().sendSpeakerRequest(request);
        }
        requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
        stateMachine.saveActionToHistory("Commands for installing ingress rules have been sent");
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext) UUID(java.util.UUID) Flow(org.openkilda.model.Flow)

Example 4 with FlowSegmentRequest

use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.

the class InstallNonIngressRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(flow);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for commandBuilder.buildAllExceptIngress() to use proper (updated) encapsulation type.
        flow.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> requestFactories = new ArrayList<>();
    if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
        requestFactories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, newForward, newReverse));
    }
    if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
        FlowPath newForward = getFlowPath(flow, stateMachine.getNewProtectedForwardPath());
        FlowPath newReverse = getFlowPath(flow, stateMachine.getNewProtectedReversePath());
        requestFactories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, newForward, newReverse));
    }
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    if (requestFactories.isEmpty()) {
        stateMachine.saveActionToHistory("No need to install non ingress rules");
        stateMachine.fire(Event.RULES_INSTALLED);
    } else {
        Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getNonIngressCommands();
        for (FlowSegmentRequestFactory factory : requestFactories) {
            FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
            // TODO ensure no conflicts
            requestsStorage.put(request.getCommandId(), factory);
            stateMachine.getCarrier().sendSpeakerRequest(request);
        }
        requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
        stateMachine.saveActionToHistory("Commands for installing non ingress rules have been sent");
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) UUID(java.util.UUID) Flow(org.openkilda.model.Flow)

Example 5 with FlowSegmentRequest

use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.

the class SpeakerWorkerService method handleTimeout.

/**
 * Handles operation timeout.
 * @param key operation identifier.
 */
public void handleTimeout(@NonNull String key) throws PipelineException {
    SpeakerRequest failedRequest = keyToRequest.remove(key);
    if (failedRequest instanceof FlowSegmentRequest) {
        FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) failedRequest;
        SpeakerFlowSegmentResponse response = FlowErrorResponse.errorBuilder().commandId(flowSegmentRequest.getCommandId()).switchId(flowSegmentRequest.getSwitchId()).metadata(flowSegmentRequest.getMetadata()).errorCode(ErrorCode.OPERATION_TIMED_OUT).messageContext(flowSegmentRequest.getMessageContext()).build();
        carrier.sendResponse(key, response);
    } else if (failedRequest instanceof BaseSpeakerCommandsRequest) {
        BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) failedRequest;
        SpeakerCommandResponse response = SpeakerCommandResponse.builder().commandId(speakerCommandsRequest.getCommandId()).switchId(speakerCommandsRequest.getSwitchId()).messageContext(speakerCommandsRequest.getMessageContext()).success(false).failedCommandIds(speakerCommandsRequest.getCommands().stream().map(command -> {
            if (command instanceof FlowCommand) {
                return ((FlowCommand) command).getData();
            }
            if (command instanceof MeterCommand) {
                return ((MeterCommand) command).getData();
            }
            return ((GroupCommand) command).getData();
        }).collect(Collectors.toMap(SpeakerData::getUuid, error -> "Operation is timed out"))).build();
        carrier.sendResponse(key, response);
    }
}
Also used : GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) SpeakerData(org.openkilda.rulemanager.SpeakerData)

Aggregations

FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)65 Flow (org.openkilda.model.Flow)38 Test (org.junit.Test)31 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)23 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)21 CommandContext (org.openkilda.wfm.CommandContext)15 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)14 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)12 UUID (java.util.UUID)10 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)9 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)9 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 FlowPath (org.openkilda.model.FlowPath)6 GetPathsResult (org.openkilda.pce.GetPathsResult)6 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)6 ArrayList (java.util.ArrayList)5 Ignore (org.junit.Ignore)4 SpeakerRequest (org.openkilda.floodlight.api.request.SpeakerRequest)4 FlowEndpoint (org.openkilda.model.FlowEndpoint)4 FlowPathSwapRequest (org.openkilda.messaging.command.flow.FlowPathSwapRequest)3