Search in sources :

Example 26 with FlowSegmentRequest

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

the class FlowUpdateServiceTest method shouldFailUpdateOnTimeoutDuringInstallation.

@Test
public void shouldFailUpdateOnTimeoutDuringInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
    FlowUpdateService service = makeService();
    service.handleUpdateRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    service.handleTimeout(dummyRequestKey);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isRemoveRequest()) {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 27 with FlowSegmentRequest

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

the class FlowUpdateServiceTest method shouldFailUpdateOnSwapPathsError.

@Ignore("FIXME: need to replace mocking of updateStatus with another approach")
@Test
public void shouldFailUpdateOnSwapPathsError() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
    FlowPathRepository flowPathRepository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(flowPathRepository).updateStatus(eq(origin.getForwardPathId()), eq(FlowPathStatus.IN_PROGRESS));
    FlowUpdateService service = makeService();
    service.handleUpdateRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with FlowSegmentRequest

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

the class FlowUpdateServiceTest method shouldSuccessfullyUpdateFlowDeleteFlowLoop.

@Test
public void shouldSuccessfullyUpdateFlowDeleteFlowLoop() throws DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    transactionManager.doInTransaction(() -> {
        Flow flow = repositoryFactory.createFlowRepository().findById(origin.getFlowId()).get();
        flow.setLoopSwitchId(origin.getDestSwitchId());
    });
    DeleteFlowLoopRequest request = new DeleteFlowLoopRequest(origin.getFlowId());
    FlowUpdateService service = makeService();
    service.handleDeleteFlowLoopRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    Set<Class> allowedRequestTypes = Sets.newHashSet(IngressFlowLoopSegmentRemoveRequest.class, TransitFlowLoopSegmentRemoveRequest.class);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (!allowedRequestTypes.contains(speakerRequest.getClass())) {
            throw new IllegalStateException(String.format("Not allowed request found %s", speakerRequest));
        }
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    assertFalse(result.isLooped());
    assertNull(result.getLoopSwitchId());
}
Also used : DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 29 with FlowSegmentRequest

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

the class FlowUpdateServiceTest method shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation.

@Test
public void shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(Collectors.toSet());
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
    FlowUpdateService service = makeService();
    service.handleUpdateRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : PathId(org.openkilda.model.PathId) ArgumentMatchers(org.mockito.ArgumentMatchers) FlowPath(org.openkilda.model.FlowPath) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IngressFlowLoopSegmentRemoveRequest(org.openkilda.floodlight.api.request.IngressFlowLoopSegmentRemoveRequest) FlowStatus(org.openkilda.model.FlowStatus) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) TransitFlowLoopSegmentInstallRequest(org.openkilda.floodlight.api.request.TransitFlowLoopSegmentInstallRequest) Mockito.doThrow(org.mockito.Mockito.doThrow) FlowPathStatus(org.openkilda.model.FlowPathStatus) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Flow(org.openkilda.model.Flow) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Mockito.doReturn(org.mockito.Mockito.doReturn) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ErrorCode(org.openkilda.floodlight.flow.response.FlowErrorResponse.ErrorCode) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) Mock(org.mockito.Mock) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) RunWith(org.junit.runner.RunWith) RecoverableException(org.openkilda.pce.exception.RecoverableException) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) IslRepository(org.openkilda.persistence.repositories.IslRepository) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) PathId(org.openkilda.model.PathId) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Before(org.junit.Before) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException) DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) ErrorType(org.openkilda.messaging.error.ErrorType) IngressFlowLoopSegmentVerifyRequest(org.openkilda.floodlight.api.request.IngressFlowLoopSegmentVerifyRequest) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) GetPathsResult(org.openkilda.pce.GetPathsResult) TransitFlowLoopSegmentRemoveRequest(org.openkilda.floodlight.api.request.TransitFlowLoopSegmentRemoveRequest) Assert(org.junit.Assert) IngressFlowLoopSegmentInstallRequest(org.openkilda.floodlight.api.request.IngressFlowLoopSegmentInstallRequest) TransitFlowLoopSegmentVerifyRequest(org.openkilda.floodlight.api.request.TransitFlowLoopSegmentVerifyRequest) Assert.assertEquals(org.junit.Assert.assertEquals) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 30 with FlowSegmentRequest

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

the class FlowUpdateServiceTest method shouldSuccessfullyUpdateFlowCreateFlowLoop.

@Test
public void shouldSuccessfullyUpdateFlowCreateFlowLoop() throws DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    CreateFlowLoopRequest request = new CreateFlowLoopRequest(origin.getFlowId(), origin.getSrcSwitchId());
    FlowUpdateService service = makeService();
    service.handleCreateFlowLoopRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    Set<Class> allowedRequestTypes = Sets.newHashSet(IngressFlowLoopSegmentInstallRequest.class, IngressFlowLoopSegmentVerifyRequest.class, TransitFlowLoopSegmentInstallRequest.class, TransitFlowLoopSegmentVerifyRequest.class);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (!allowedRequestTypes.contains(speakerRequest.getClass())) {
            throw new IllegalStateException(String.format("Not allowed request found %s", speakerRequest));
        }
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    assertTrue(result.isLooped());
    assertEquals(request.getSwitchId(), result.getLoopSwitchId());
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

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