Search in sources :

Example 11 with PathId

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

the class SwapFlowPathsAction method swapPrimaryPaths.

private void swapPrimaryPaths(FlowUpdateFsm stateMachine) {
    PathId newForward = stateMachine.getNewPrimaryForwardPath();
    PathId newReverse = stateMachine.getNewPrimaryReversePath();
    if (newForward != null && newReverse != null) {
        transactionManager.doInTransaction(() -> {
            Flow flow = getFlow(stateMachine.getFlowId());
            FlowPath oldForward = flow.getForwardPath();
            if (oldForward != null) {
                stateMachine.setOldPrimaryForwardPath(oldForward.getPathId());
                stateMachine.setOldPrimaryForwardPathStatus(oldForward.getStatus());
                oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            FlowPath oldReverse = flow.getReversePath();
            if (oldReverse != null) {
                stateMachine.setOldPrimaryReversePath(oldReverse.getPathId());
                stateMachine.setOldPrimaryReversePathStatus(oldReverse.getStatus());
                oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            if (oldForward != null || oldReverse != null) {
                FlowEncapsulationType oldFlowEncapsulationType = stateMachine.getOriginalFlow().getFlowEncapsulationType();
                FlowResources oldResources = getResources(oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward, oldFlowEncapsulationType);
                stateMachine.getOldResources().add(oldResources);
            }
            flow.setForwardPathId(newForward);
            flow.setReversePathId(newReverse);
            log.debug("Swapping the primary paths {}/{} with {}/{}", oldForward != null ? oldForward.getPathId() : null, oldReverse != null ? oldReverse.getPathId() : null, newForward, newReverse);
        });
        saveHistory(stateMachine, stateMachine.getFlowId(), newForward, newReverse);
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 12 with PathId

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

the class CompleteFlowPathInstallationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    PathId newPrimaryForward = stateMachine.getNewPrimaryForwardPath();
    PathId newPrimaryReverse = stateMachine.getNewPrimaryReversePath();
    FlowPathStatus primaryPathStatus;
    if (stateMachine.isBackUpPrimaryPathComputationWayUsed()) {
        primaryPathStatus = FlowPathStatus.DEGRADED;
    } else {
        primaryPathStatus = FlowPathStatus.ACTIVE;
    }
    log.debug("Completing installation of the flow primary path {} / {}", newPrimaryForward, newPrimaryReverse);
    transactionManager.doInTransaction(() -> {
        flowPathRepository.updateStatus(newPrimaryForward, primaryPathStatus);
        flowPathRepository.updateStatus(newPrimaryReverse, primaryPathStatus);
    });
    stateMachine.saveActionToHistory("Flow paths were installed", format("The flow paths %s / %s were installed", newPrimaryForward, newPrimaryReverse));
    if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
        PathId newForward = stateMachine.getNewProtectedForwardPath();
        PathId newReverse = stateMachine.getNewProtectedReversePath();
        FlowPathStatus protectedPathStatus;
        if (stateMachine.isBackUpProtectedPathComputationWayUsed()) {
            protectedPathStatus = FlowPathStatus.DEGRADED;
        } else {
            protectedPathStatus = FlowPathStatus.ACTIVE;
        }
        log.debug("Completing installation of the flow protected path {} / {}", newForward, newReverse);
        transactionManager.doInTransaction(() -> {
            flowPathRepository.updateStatus(newForward, protectedPathStatus);
            flowPathRepository.updateStatus(newReverse, protectedPathStatus);
        });
        stateMachine.saveActionToHistory("Flow paths were installed", format("The flow paths %s / %s were installed", newForward, newReverse));
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowPathStatus(org.openkilda.model.FlowPathStatus)

Example 13 with PathId

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

the class AllocateProtectedResourcesAction 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 protected path ids for flows {}", flowIds);
    List<PathId> pathIdsToReuse = new ArrayList<>(flowPathRepository.findActualPathIdsByFlowIds(flowIds));
    pathIdsToReuse.addAll(stateMachine.getRejectedPaths());
    Flow tmpFlow = getFlow(flowId);
    FlowPathPair oldPaths = new FlowPathPair(tmpFlow.getProtectedForwardPath(), tmpFlow.getProtectedReversePath());
    FlowPath primaryForward = getFlowPath(tmpFlow, stateMachine.getNewPrimaryForwardPath());
    FlowPath primaryReverse = getFlowPath(tmpFlow, stateMachine.getNewPrimaryReversePath());
    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);
    log.debug("Finding a new protected path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlow, newForwardPathId, newReversePathId, false, pathIdsToReuse, oldPaths, true, stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
    if (allocatedPaths == null) {
        throw new ResourceAllocationException("Unable to allocate a path");
    }
    if (!testNonOverlappingPath.test(allocatedPaths)) {
        stateMachine.saveActionToHistory("Couldn't find non overlapping protected path");
    } else {
        log.debug("New protected paths have been allocated: {}", allocatedPaths);
        stateMachine.setNewProtectedForwardPath(newForwardPathId);
        stateMachine.setNewProtectedReversePath(newReversePathId);
        stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        log.debug("Allocating resources for a new protected path of flow {}", flowId);
        FlowResources flowResources = allocateFlowResources(tmpFlow, newForwardPathId, newReversePathId);
        stateMachine.setNewProtectedResources(flowResources);
        FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, false, stateMachine.getSharedBandwidthGroupId());
        log.debug("New protected path has been created: {}", createdPaths);
        saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlow, "protected", createdPaths);
    }
}
Also used : BaseResourceAllocationAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseResourceAllocationAction) FlowPath(org.openkilda.model.FlowPath) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) RecoverableException(org.openkilda.pce.exception.RecoverableException) ArrayList(java.util.ArrayList) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) ErrorType(org.openkilda.messaging.error.ErrorType) Predicate(java.util.function.Predicate) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) Set(java.util.Set) State(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.State) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Sets(com.google.common.collect.Sets) Event(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.Event) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) PathComputer(org.openkilda.pce.PathComputer) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) ArrayList(java.util.ArrayList) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException)

Example 14 with PathId

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

the class CompleteFlowPathRemovalAction method removeOldProtectedFlowPaths.

private void removeOldProtectedFlowPaths(Flow originalFlow, FlowUpdateFsm 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, originalFlow, removedPaths);
        }
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair)

Example 15 with PathId

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

the class CompleteFlowPathRemovalAction method removeOldPrimaryFlowPaths.

private void removeOldPrimaryFlowPaths(Flow originalFlow, FlowUpdateFsm 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, originalFlow, removedPaths);
        }
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair)

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