Search in sources :

Example 16 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class BaseResourceAllocationActionTest method updateAvailableBandwidthFailsOnOverProvisionTest.

@Test(expected = ResourceAllocationException.class)
public void updateAvailableBandwidthFailsOnOverProvisionTest() throws ResourceAllocationException {
    islRepositorySpy = spy(persistenceManager.getRepositoryFactory().createIslRepository());
    when(repositoryFactory.createIslRepository()).thenReturn(islRepositorySpy);
    doReturn(-1L).when(islRepositorySpy).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
    BaseResourceAllocationAction action = mock(BaseResourceAllocationAction.class, Mockito.withSettings().useConstructor(persistenceManager, 3, 3, 3, pathComputer, resourcesManager, dashboardLogger).defaultAnswer(Mockito.CALLS_REAL_METHODS));
    PathSegment segment = PathSegment.builder().pathId(new PathId("")).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).srcPort(1).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).destPort(2).build();
    action.createPathSegments(singletonList(segment), Suppliers.ofInstance(emptyMap()));
}
Also used : PathId(org.openkilda.model.PathId) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 17 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation.

@Test
public void shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(toSet());
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
    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 : PathId(org.openkilda.model.PathId) MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) ArgumentMatchers(org.mockito.ArgumentMatchers) FlowPath(org.openkilda.model.FlowPath) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FlowStatus(org.openkilda.model.FlowStatus) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) 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) Collectors.toSet(java.util.stream.Collectors.toSet) IslEndpoint(org.openkilda.model.IslEndpoint) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) CommandContext(org.openkilda.wfm.CommandContext) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) List(java.util.List) 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) RerouteResultInfoData(org.openkilda.messaging.info.reroute.RerouteResultInfoData) PathSegment(org.openkilda.model.PathSegment) Mock(org.mockito.Mock) 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) FlowRerouteResponse(org.openkilda.messaging.info.flow.FlowRerouteResponse) PathId(org.openkilda.model.PathId) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Before(org.junit.Before) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorType(org.openkilda.messaging.error.ErrorType) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) Mockito.verify(org.mockito.Mockito.verify) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) GetPathsResult(org.openkilda.pce.GetPathsResult) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) 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) Test(org.junit.Test)

Example 18 with PathId

use of org.openkilda.model.PathId 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 19 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths.

@Test
public void shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths() throws Exception {
    Flow flow = getFlow(false);
    IslImmutableView isl = getIslView(flow);
    PathId pathId = new PathId("flow-path-id");
    FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).ignoreBandwidth(true).build();
    when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
    when(islRepository.findSymmetricActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
    when(flowPathRepository.findById(pathId)).thenReturn(Optional.of(flowPath));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.singletonList(pathId));
    assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 20 with PathId

use of org.openkilda.model.PathId in project open-kilda by telstra.

the class AvailableNetworkFactoryTest method shouldIncreaseDiversityGroupUseCounter.

@Test
public void shouldIncreaseDiversityGroupUseCounter() throws RecoverableException {
    // Topology:
    // A----B----C     Already created flow: B-D
    // |          Requested flow: A-B-C
    // D
    // there is no ISL B-D because we assume that is has no enough bandwidth
    List<IslImmutableView> isls = new ArrayList<>();
    isls.addAll(getBidirectionalIsls(switchA, 1, switchB, 2));
    isls.addAll(getBidirectionalIsls(switchB, 3, switchC, 4));
    FlowPath forwardPath = FlowPath.builder().srcSwitch(switchB).destSwitch(switchD).pathId(FORWARD_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(FORWARD_PATH_ID).srcSwitch(switchB).srcPort(SRC_PORT).destSwitch(switchD).destPort(DEST_PORT).build())).build();
    when(flowPathRepository.findById(FORWARD_PATH_ID)).thenReturn(java.util.Optional.of(forwardPath));
    FlowPath reversePath = FlowPath.builder().srcSwitch(switchD).destSwitch(switchB).pathId(REVERSE_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(REVERSE_PATH_ID).srcSwitch(switchD).srcPort(DEST_PORT).destSwitch(switchB).destPort(SRC_PORT).build())).build();
    when(flowPathRepository.findById(REVERSE_PATH_ID)).thenReturn(java.util.Optional.of(reversePath));
    Flow flow = getFlow(false);
    flow.setSrcSwitch(switchA);
    flow.setDestSwitch(switchC);
    flow.setDiverseGroupId(DIVERSE_GROUP_ID);
    flow.setForwardPathId(new PathId("forward_path_id"));
    flow.setReversePathId(new PathId("reverse_path_id"));
    when(config.getNetworkStrategy()).thenReturn(BuildStrategy.COST.name());
    when(islRepository.findActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(isls);
    when(flowPathRepository.findPathIdsByFlowDiverseGroupId(DIVERSE_GROUP_ID)).thenReturn(Lists.newArrayList(FORWARD_PATH_ID, REVERSE_PATH_ID));
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    assertEquals(2, availableNetwork.getSwitch(switchB.getSwitchId()).getDiversityGroupUseCounter());
}
Also used : IslImmutableView(org.openkilda.persistence.repositories.IslRepository.IslImmutableView) PathId(org.openkilda.model.PathId) ArrayList(java.util.ArrayList) FlowPath(org.openkilda.model.FlowPath) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

PathId (org.openkilda.model.PathId)124 Flow (org.openkilda.model.Flow)65 FlowPath (org.openkilda.model.FlowPath)65 Test (org.junit.Test)44 Switch (org.openkilda.model.Switch)29 SwitchId (org.openkilda.model.SwitchId)28 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)27 PathSegment (org.openkilda.model.PathSegment)26 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)21 MeterId (org.openkilda.model.MeterId)19 ArrayList (java.util.ArrayList)18 List (java.util.List)13 Slf4j (lombok.extern.slf4j.Slf4j)11 GetPathsResult (org.openkilda.pce.GetPathsResult)11 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)10 Path (org.openkilda.pce.Path)10 Collection (java.util.Collection)9 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 String.format (java.lang.String.format)8 HashMap (java.util.HashMap)8