Search in sources :

Example 21 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldSuccessfullyHandleOverlappingRequests.

@Test
public void shouldSuccessfullyHandleOverlappingRequests() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    origin.setStatus(FlowStatus.DOWN);
    transactionManager.doInTransaction(() -> repositoryFactory.createFlowRepository().updateStatus(origin.getFlowId(), FlowStatus.DOWN));
    when(pathComputer.getPath(makeFlowArgumentMatch(origin.getFlowId()), any())).thenReturn(make2SwitchAltPathPair()).thenReturn(make3SwitchesPathPair());
    FlowRerouteService service = makeService();
    FlowRerouteRequest rerouteRequest = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, rerouteRequest, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    String overlappingKey = dummyRequestKey + "2";
    service.handleRequest(overlappingKey, rerouteRequest, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    FlowSegmentRequest request;
    while ((request = requests.poll()) != null) {
        produceAsyncResponse(service, request);
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyPathReplace(origin, result);
    FlowPath forwardPath = result.getForwardPath();
    Assert.assertNotNull(forwardPath);
    // second request is dropped
    Assert.assertEquals(1, forwardPath.getSegments().size());
    verify(carrier).sendRerouteResultStatus(eq(origin.getFlowId()), argThat(hasProperty("message", equalTo("Reroute is in progress"))), any(String.class));
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 22 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldMakeFlowDownOnTimeoutIfEffectivelyDown.

@Test
public void shouldMakeFlowDownOnTimeoutIfEffectivelyDown() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, true, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    service.handleTimeout(currentRequestKey);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        produceAsyncResponse(service, speakerRequest);
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.DOWN);
    verifyNoPathReplace(origin, result);
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 23 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldSuccessfullyRerouteFlow.

@Test
public void shouldSuccessfullyRerouteFlow() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    origin.setStatus(FlowStatus.DOWN);
    transactionManager.doInTransaction(() -> repositoryFactory.createFlowRepository().updateStatus(origin.getFlowId(), FlowStatus.DOWN));
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        produceAsyncResponse(service, speakerRequest);
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyPathReplace(origin, result);
    RerouteResultInfoData expected = RerouteResultInfoData.builder().flowId(origin.getFlowId()).success(true).build();
    verify(carrier).sendRerouteResultStatus(eq(origin.getFlowId()), isNull(), any(String.class));
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) RerouteResultInfoData(org.openkilda.messaging.info.reroute.RerouteResultInfoData) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 24 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteOnTimeoutDuringInstallation.

@Test
public void shouldFailRerouteOnTimeoutDuringInstallation() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    GetPathsResult newPathPair = make3SwitchesPathPair();
    preparePathComputation(origin.getFlowId(), newPathPair);
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    service.handleTimeout(currentRequestKey);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        produceAsyncResponse(service, speakerRequest);
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
    verify(carrier).sendRerouteResultStatus(eq(origin.getFlowId()), argThat(hasProperty("message", equalTo("Failed to install rules"))), any(String.class));
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 25 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteOnSwapPathsError.

@Ignore("FIXME: need to replace mocking of updateStatus with another approach")
@Test
public void shouldFailRerouteOnSwapPathsError() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository flowPathRepository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(flowPathRepository).updateStatus(eq(origin.getForwardPathId()), eq(FlowPathStatus.IN_PROGRESS));
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(currentRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            produceAsyncResponse(service, speakerRequest);
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)49 Test (org.junit.Test)27 Flow (org.openkilda.model.Flow)23 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)14 Values (org.apache.storm.tuple.Values)10 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)9 CommandMessage (org.openkilda.messaging.command.CommandMessage)8 IslEndpoint (org.openkilda.model.IslEndpoint)8 CommandContext (org.openkilda.wfm.CommandContext)7 FlowPath (org.openkilda.model.FlowPath)6 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)5 RerouteResultInfoData (org.openkilda.messaging.info.reroute.RerouteResultInfoData)4 GetPathsResult (org.openkilda.pce.GetPathsResult)4 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)4 HashSet (java.util.HashSet)3 RerouteQueue (org.openkilda.wfm.topology.reroute.model.RerouteQueue)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Ignore (org.junit.Ignore)2 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)2