Search in sources :

Example 41 with FlowSegmentRequest

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

the class FlowCreateServiceTest method testHappyPath.

private Flow testHappyPath(FlowRequest flowRequest, String key) throws DuplicateKeyException {
    FlowCreateService service = makeService();
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    while ((request = requests.poll()) != null) {
        try {
            if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else {
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.UP);
    verifyFlowPathStatus(result.getForwardPath(), FlowPathStatus.ACTIVE, "forward");
    verifyFlowPathStatus(result.getReversePath(), FlowPathStatus.ACTIVE, "reverse");
    return result;
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 42 with FlowSegmentRequest

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

the class RollbackInstalledRulesAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
    stateMachine.getPendingCommands().clear();
    stateMachine.getFailedCommands().clear();
    Map<UUID, SpeakerCommandObserver> pendingRequests = stateMachine.getPendingCommands();
    for (FlowSegmentRequestFactory factory : stateMachine.getSentCommands()) {
        FlowSegmentRequest request = factory.makeRemoveRequest(commandIdGenerator.generate());
        SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, request);
        commandObserver.start();
        // TODO ensure no conflicts
        pendingRequests.put(request.getCommandId(), commandObserver);
    }
    stateMachine.saveActionToHistory(String.format("Commands to rollback installed rules have been sent. Total amount: %s", pendingRequests.size()));
}
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 43 with FlowSegmentRequest

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

the class EmitVerifyRulesAction method emitVerifyRequests.

protected void emitVerifyRequests(FlowCreateFsm stateMachine, Collection<FlowSegmentRequestFactory> requestFactories) {
    final Map<UUID, SpeakerCommandObserver> pendingCommands = stateMachine.getPendingCommands();
    for (FlowSegmentRequestFactory factory : requestFactories) {
        FlowSegmentRequest request = factory.makeVerifyRequest(commandIdGenerator.generate());
        SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, Collections.singleton(ErrorCode.MISSING_OF_FLOWS), request);
        commandObserver.start();
        pendingCommands.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 44 with FlowSegmentRequest

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

the class FlowCreateServiceTest method shouldRollbackIfEgressRuleNotInstalled.

@Test
public void shouldRollbackIfEgressRuleNotInstalled() throws Exception {
    when(pathComputer.getPath(any(Flow.class))).thenReturn(make3SwitchesPathPair());
    String key = "failed_flow_create";
    FlowRequest flowRequest = makeRequest().flowId("failed_flow_id").build();
    FlowCreateService service = makeService();
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    int installCommands = 0;
    int deleteCommands = 0;
    while ((request = requests.poll()) != null) {
        try {
            if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else if (request.isInstallRequest()) {
                installCommands++;
                if (requests.size() > 1) {
                    handleResponse(service, key, request);
                } else {
                    handleErrorResponse(service, key, request, ErrorCode.UNKNOWN);
                }
            } else if (request.isRemoveRequest()) {
                deleteCommands++;
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    assertEquals("All installed rules should be deleted", installCommands, deleteCommands);
    Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    // TODO(surabujin): do we really want to create flow without paths?
    Assert.assertNull(result.getForwardPath());
    Assert.assertNull(result.getReversePath());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) Test(org.junit.Test)

Example 45 with FlowSegmentRequest

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

the class FlowCreateServiceTest method testSpeakerCommandRetry.

private void testSpeakerCommandRetry(Class<?> failRequest, ErrorCode error, boolean mustRetry) throws Exception {
    String key = "retries_non_ingress_installation";
    FlowRequest flowRequest = makeRequest().flowId("dummy_flow_id").build();
    int retriesLimit = 10;
    FlowCreateService service = makeService(retriesLimit);
    preparePathComputation(flowRequest.getFlowId(), make2SwitchesPathPair());
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    Set<UUID> producedErrors = new HashSet<>();
    Map<UUID, Integer> remainingRetries = new HashMap<>();
    Map<UUID, Integer> seenCounter = new HashMap<>();
    FlowSegmentRequest request;
    while ((request = requests.poll()) != null) {
        UUID commandId = request.getCommandId();
        seenCounter.put(commandId, seenCounter.getOrDefault(commandId, 0) + 1);
        Integer remaining = remainingRetries.getOrDefault(commandId, retriesLimit);
        try {
            if (failRequest.isInstance(request) && remaining > 0) {
                producedErrors.add(commandId);
                remainingRetries.put(commandId, remaining - 1);
                handleErrorResponse(service, key, request, error);
            } else if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else {
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    Assert.assertFalse(producedErrors.isEmpty());
    for (Map.Entry<UUID, Integer> entry : seenCounter.entrySet()) {
        if (!producedErrors.contains(entry.getKey())) {
            continue;
        }
        Integer counter = entry.getValue();
        if (mustRetry) {
            Assert.assertEquals(retriesLimit + 1, (int) counter);
        } else {
            Assert.assertEquals(1, (int) counter);
        }
    }
    if (mustRetry) {
        Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.UP);
        verifyFlowPathStatus(result.getForwardPath(), FlowPathStatus.ACTIVE, "forward");
        verifyFlowPathStatus(result.getReversePath(), FlowPathStatus.ACTIVE, "reverse");
    } else {
        verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) HashMap(java.util.HashMap) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

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