Search in sources :

Example 6 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair in project open-kilda by telstra.

the class BaseFlowPathRemovalAction method saveRemovalActionWithDumpToHistory.

protected void saveRemovalActionWithDumpToHistory(T stateMachine, Flow flow, FlowPath flowPath) {
    // TODO: History dumps require paired paths, fix it to support any (without opposite one).
    FlowPathPair pathsToDelete = FlowPathPair.builder().forward(flowPath).reverse(flowPath).build();
    saveRemovalActionWithDumpToHistory(stateMachine, flow, pathsToDelete);
}
Also used : FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair)

Example 7 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair in project open-kilda by telstra.

the class AllocatePrimaryResourcesAction method allocate.

@Override
protected void allocate(FlowUpdateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Set<String> flowIds = Sets.newHashSet(flowId);
    if (stateMachine.getBulkUpdateFlowIds() != null) {
        flowIds.addAll(stateMachine.getBulkUpdateFlowIds());
    }
    log.debug("Finding paths for flows {}", flowIds);
    List<PathId> pathIdsToReuse = new ArrayList<>(flowPathRepository.findActualPathIdsByFlowIds(flowIds));
    pathIdsToReuse.addAll(stateMachine.getRejectedPaths());
    Flow tmpFlow = getFlow(flowId);
    FlowPathPair oldPaths = new FlowPathPair(tmpFlow.getForwardPath(), tmpFlow.getReversePath());
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    log.debug("Finding a new primary path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlow, newForwardPathId, newReversePathId, false, pathIdsToReuse, oldPaths, true, stateMachine.getSharedBandwidthGroupId(), path -> true);
    if (allocatedPaths == null) {
        throw new ResourceAllocationException("Unable to allocate a path");
    }
    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(tmpFlow, newForwardPathId, newReversePathId);
    stateMachine.setNewPrimaryResources(flowResources);
    FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, false, stateMachine.getSharedBandwidthGroupId());
    log.debug("New primary path has been created: {}", createdPaths);
    setMirrorPointsToNewPath(oldPaths.getForwardPathId(), newForwardPathId);
    setMirrorPointsToNewPath(oldPaths.getReversePathId(), newReversePathId);
    saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlow, "primary", createdPaths);
}
Also used : PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) ArrayList(java.util.ArrayList) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult)

Example 8 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair 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 9 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair in project open-kilda by telstra.

the class CompleteFlowPathRemovalAction method removeOldPrimaryFlowPaths.

private void removeOldPrimaryFlowPaths(Flow flow, FlowRerouteFsm stateMachine) {
    PathId oldPrimaryForwardPathId = stateMachine.getOldPrimaryForwardPath();
    PathId oldPrimaryReversePathId = stateMachine.getOldPrimaryReversePath();
    if (oldPrimaryForwardPathId != null || oldPrimaryReversePathId != null) {
        FlowPath oldPrimaryForward = flowPathRepository.remove(oldPrimaryForwardPathId).orElse(null);
        FlowPath oldPrimaryReverse = flowPathRepository.remove(oldPrimaryReversePathId).orElse(null);
        FlowPathPair removedPaths = null;
        if (oldPrimaryForward != null) {
            if (oldPrimaryReverse != null) {
                log.debug("Removed the flow paths {} / {}", oldPrimaryForward, oldPrimaryReverse);
                removedPaths = new FlowPathPair(oldPrimaryForward, oldPrimaryReverse);
                updateIslsForFlowPath(removedPaths.getForward(), removedPaths.getReverse());
            } else {
                log.debug("Removed the flow path {} (no reverse pair)", oldPrimaryForward);
                // TODO: History dumps require paired paths, fix it to support any (without opposite one).
                removedPaths = new FlowPathPair(oldPrimaryForward, oldPrimaryForward);
                updateIslsForFlowPath(removedPaths.getForward());
            }
        } else if (oldPrimaryReverse != null) {
            log.debug("Removed the flow path {} (no forward pair)", oldPrimaryReverse);
            // TODO: History dumps require paired paths, fix it to support any (without opposite one).
            removedPaths = new FlowPathPair(oldPrimaryReverse, oldPrimaryReverse);
            updateIslsForFlowPath(removedPaths.getReverse());
        }
        if (removedPaths != null) {
            saveRemovalActionWithDumpToHistory(stateMachine, flow, removedPaths);
        }
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair)

Example 10 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair in project open-kilda by telstra.

the class CompleteFlowPathRemovalAction method removeOldProtectedFlowPaths.

private void removeOldProtectedFlowPaths(Flow flow, FlowRerouteFsm stateMachine) {
    PathId oldProtectedForwardPathId = stateMachine.getOldProtectedForwardPath();
    PathId oldProtectedReversePathId = stateMachine.getOldProtectedReversePath();
    if (oldProtectedForwardPathId != null || oldProtectedReversePathId != null) {
        FlowPath oldProtectedForward = flowPathRepository.remove(oldProtectedForwardPathId).orElse(null);
        FlowPath oldProtectedReverse = flowPathRepository.remove(oldProtectedReversePathId).orElse(null);
        FlowPathPair removedPaths = null;
        if (oldProtectedForward != null) {
            if (oldProtectedReverse != null) {
                log.debug("Removed the flow paths {} / {}", oldProtectedForward, oldProtectedReverse);
                removedPaths = new FlowPathPair(oldProtectedForward, oldProtectedReverse);
                updateIslsForFlowPath(removedPaths.getForward(), removedPaths.getReverse());
            } else {
                log.debug("Removed the flow path {} (no reverse pair)", oldProtectedForward);
                // TODO: History dumps require paired paths, fix it to support any (without opposite one).
                removedPaths = new FlowPathPair(oldProtectedForward, oldProtectedForward);
                updateIslsForFlowPath(removedPaths.getForward());
            }
        } else if (oldProtectedReverse != null) {
            log.debug("Removed the flow path {} (no forward pair)", oldProtectedReverse);
            // TODO: History dumps require paired paths, fix it to support any (without opposite one).
            removedPaths = new FlowPathPair(oldProtectedReverse, oldProtectedReverse);
            updateIslsForFlowPath(removedPaths.getReverse());
        }
        if (removedPaths != null) {
            saveRemovalActionWithDumpToHistory(stateMachine, flow, removedPaths);
        }
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair)

Aggregations

FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)12 PathId (org.openkilda.model.PathId)10 FlowPath (org.openkilda.model.FlowPath)9 Flow (org.openkilda.model.Flow)7 GetPathsResult (org.openkilda.pce.GetPathsResult)5 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)5 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Predicate (java.util.function.Predicate)3 Slf4j (lombok.extern.slf4j.Slf4j)3 ErrorType (org.openkilda.messaging.error.ErrorType)3 PathComputer (org.openkilda.pce.PathComputer)3 RecoverableException (org.openkilda.pce.exception.RecoverableException)3 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)3 PersistenceManager (org.openkilda.persistence.PersistenceManager)3 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)3 FlowOperationsDashboardLogger (org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger)3 TimedExecution (org.openkilda.wfm.share.metrics.TimedExecution)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1