Search in sources :

Example 46 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class MaxLatencyPathComputationStrategyBaseTest method shouldUseSlowLinkInsidePath.

@Test
public void shouldUseSlowLinkInsidePath() throws Exception {
    createTwoLinksInsidePathTopo();
    Flow flow = Flow.builder().flowId("test flow").srcSwitch(getSwitchById("00:01")).srcPort(15).destSwitch(getSwitchById("00:06")).destPort(15).bandwidth(500).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).maxLatency(30L).build();
    PathComputer pathComputer = pathComputerFactory.getPathComputer();
    GetPathsResult path = pathComputer.getPath(flow);
    assertNotNull(path);
    assertEquals(path.getForward().getSegments().size(), 5);
    assertEquals(path.getForward().getLatency(), 14);
}
Also used : PathComputer(org.openkilda.pce.PathComputer) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 47 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class MaxLatencyPathComputationStrategyBaseTest method maxLatencyStratWithZeroLatency.

/**
 * Special case: flow with MAX_LATENCY strategy and 'max-latency' set to 0 should pick path with least latency.
 */
@Test
public void maxLatencyStratWithZeroLatency() throws RecoverableException, UnroutableFlowException {
    // 1 - 2 - 4
    // + 3 +
    // path 1>2>4 has less latency than 1>3>4
    createDiamond(IslStatus.ACTIVE, IslStatus.ACTIVE, 100, 100, "00:", 1, 100, 101);
    // when: request a flow with MAX_LATENCY strategy and 'max-latency' set to 0
    Flow flow = Flow.builder().flowId("test flow").srcSwitch(getSwitchById("00:01")).srcPort(15).destSwitch(getSwitchById("00:04")).destPort(15).bandwidth(500).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).pathComputationStrategy(PathComputationStrategy.MAX_LATENCY).maxLatency(0L).build();
    PathComputer pathComputer = new InMemoryPathComputer(availableNetworkFactory, new BestWeightAndShortestPathFinder(5), config);
    GetPathsResult pathsResult = pathComputer.getPath(flow);
    // then: system returns a path with least weight
    assertFalse(pathsResult.isBackUpPathComputationWayUsed());
    assertThat(pathsResult.getForward().getSegments().get(1).getSrcSwitchId(), equalTo(new SwitchId("00:02")));
    assertThat(pathsResult.getReverse().getSegments().get(1).getSrcSwitchId(), equalTo(new SwitchId("00:02")));
}
Also used : PathComputer(org.openkilda.pce.PathComputer) BestWeightAndShortestPathFinder(org.openkilda.pce.finder.BestWeightAndShortestPathFinder) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) GetPathsResult(org.openkilda.pce.GetPathsResult) Test(org.junit.Test)

Example 48 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteOnTimeoutDuringValidation.

@Test
public void shouldFailRerouteOnTimeoutDuringValidation() 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);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleTimeout(currentRequestKey);
        } else {
            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 validate 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 49 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class AllocateProtectedResourcesAction method allocate.

@TimedExecution("fsm.resource_allocation_protected")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlowCopy = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(tmpFlowCopy);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for PCE to use proper (updated) encapsulation type.
        tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
    FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
    FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
    Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
    pathsToReuse.addAll(stateMachine.getRejectedPaths());
    log.debug("Finding a new protected path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
    if (allocatedPaths != null) {
        stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        if (!testNonOverlappingPath.test(allocatedPaths)) {
            stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
            stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
        } else {
            log.debug("New protected paths have been allocated: {}", allocatedPaths);
            stateMachine.setNewProtectedForwardPath(newForwardPathId);
            stateMachine.setNewProtectedReversePath(newReversePathId);
            log.debug("Allocating resources for a new protected path of flow {}", flowId);
            FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
            stateMachine.setNewProtectedResources(flowResources);
            FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
            log.debug("New protected paths have been created: {}", createdPaths);
            saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
        }
    } else {
        stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
    }
}
Also used : FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) BaseResourceAllocationAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseResourceAllocationAction) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) FlowPath(org.openkilda.model.FlowPath) ErrorType(org.openkilda.messaging.error.ErrorType) Predicate(java.util.function.Predicate) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) RecoverableException(org.openkilda.pce.exception.RecoverableException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) State(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.State) Lists(com.google.common.collect.Lists) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PathComputer(org.openkilda.pce.PathComputer) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 50 with GetPathsResult

use of org.openkilda.pce.GetPathsResult in project open-kilda by telstra.

the class AllocatePrimaryResourcesAction method allocate.

@TimedExecution("fsm.resource_allocation_primary")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlowCopy = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(tmpFlowCopy);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for PCE to use proper (updated) encapsulation type.
        tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getForwardPath(), tmpFlowCopy.getReversePath());
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getForwardPathId(), tmpFlowCopy.getReversePathId());
    pathsToReuse.addAll(stateMachine.getRejectedPaths());
    log.debug("Finding a new primary path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), path -> true);
    if (allocatedPaths != null) {
        log.debug("New primary paths have been allocated: {}", allocatedPaths);
        stateMachine.setBackUpPrimaryPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        stateMachine.setNewPrimaryForwardPath(newForwardPathId);
        stateMachine.setNewPrimaryReversePath(newReversePathId);
        log.debug("Allocating resources for a new primary path of flow {}", flowId);
        FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
        stateMachine.setNewPrimaryResources(flowResources);
        FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
        log.debug("New primary paths have been created: {}", createdPaths);
        setMirrorPointsToNewPath(oldPaths.getForwardPathId(), newForwardPathId);
        setMirrorPointsToNewPath(oldPaths.getReversePathId(), newReversePathId);
        saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "primary", createdPaths);
    } else {
        stateMachine.saveActionToHistory("Found the same primary path. Skipped creating of it");
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Aggregations

Flow (org.openkilda.model.Flow)50 GetPathsResult (org.openkilda.pce.GetPathsResult)50 PathComputer (org.openkilda.pce.PathComputer)42 Test (org.junit.Test)40 SwitchId (org.openkilda.model.SwitchId)30 Switch (org.openkilda.model.Switch)22 FlowPath (org.openkilda.model.FlowPath)8 PathId (org.openkilda.model.PathId)8 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)7 PathSegment (org.openkilda.model.PathSegment)5 BestWeightAndShortestPathFinder (org.openkilda.pce.finder.BestWeightAndShortestPathFinder)5 FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)5 ArrayList (java.util.ArrayList)4 Segment (org.openkilda.pce.Path.Segment)4 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)4 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)4 List (java.util.List)3 Predicate (java.util.function.Predicate)3 Slf4j (lombok.extern.slf4j.Slf4j)3 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)3