Search in sources :

Example 81 with PathId

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

the class SwapFlowPathsAction method swapProtectedPaths.

private void swapProtectedPaths(FlowRerouteFsm stateMachine) {
    PathId newForward = stateMachine.getNewProtectedForwardPath();
    PathId newReverse = stateMachine.getNewProtectedReversePath();
    if (newForward != null && newReverse != null) {
        transactionManager.doInTransaction(() -> {
            Flow flow = getFlow(stateMachine.getFlowId());
            FlowPath oldForward = flow.getProtectedForwardPath();
            if (oldForward != null) {
                stateMachine.setOldProtectedForwardPath(oldForward.getPathId());
                stateMachine.setOldProtectedForwardPathStatus(oldForward.getStatus());
                oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            FlowPath oldReverse = flow.getProtectedReversePath();
            if (oldReverse != null) {
                stateMachine.setOldProtectedReversePath(oldReverse.getPathId());
                stateMachine.setOldProtectedReversePathStatus(oldReverse.getStatus());
                oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            if (oldForward != null || oldReverse != null) {
                FlowResources oldResources = getResources(flow, oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward);
                stateMachine.getOldResources().add(oldResources);
            }
            flow.setProtectedForwardPathId(newForward);
            flow.setProtectedReversePathId(newReverse);
            log.debug("Swapping the protected 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) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 82 with PathId

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

the class SwapFlowPathsAction method swapPrimaryPaths.

private void swapPrimaryPaths(FlowRerouteFsm 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) {
                FlowResources oldResources = getResources(flow, oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward);
                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) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 83 with PathId

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

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

the class SwapFlowPathsAction method swapProtectedPaths.

private void swapProtectedPaths(FlowUpdateFsm stateMachine) {
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(stateMachine.getFlowId());
        FlowPath oldForward = flow.getProtectedForwardPath();
        if (oldForward != null) {
            stateMachine.setOldProtectedForwardPath(oldForward.getPathId());
            stateMachine.setOldProtectedForwardPathStatus(oldForward.getStatus());
            oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
        }
        FlowPath oldReverse = flow.getProtectedReversePath();
        if (oldReverse != null) {
            stateMachine.setOldProtectedReversePath(oldReverse.getPathId());
            stateMachine.setOldProtectedReversePathStatus(oldReverse.getStatus());
            oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
        }
        if (oldForward != null || oldReverse != null) {
            FlowEncapsulationType oldFlowEncapsulationType = stateMachine.getOriginalFlow().getFlowEncapsulationType();
            FlowResources oldProtectedResources = getResources(oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward, oldFlowEncapsulationType);
            stateMachine.getOldResources().add(oldProtectedResources);
        }
        PathId newForward = stateMachine.getNewProtectedForwardPath();
        PathId newReverse = stateMachine.getNewProtectedReversePath();
        flow.setProtectedForwardPathId(newForward);
        flow.setProtectedReversePathId(newReverse);
        if (newForward != null && newReverse != null) {
            log.debug("Swapping the protected 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 85 with PathId

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

the class InMemoryPathComputerBaseTest method createLinearTopoWithFlowSegments.

private void createLinearTopoWithFlowSegments(int cost, String switchStart, int startIndex, long linkBw, String flowId, long flowBandwidth) {
    // A - B - C
    int index = startIndex;
    Switch nodeA = createSwitch(switchStart + format("%02X", index++));
    Switch nodeB = createSwitch(switchStart + format("%02X", index++));
    Switch nodeC = createSwitch(switchStart + format("%02X", index));
    createIsl(nodeA, nodeB, IslStatus.ACTIVE, IslStatus.ACTIVE, cost, linkBw, 5);
    createIsl(nodeB, nodeC, IslStatus.ACTIVE, IslStatus.ACTIVE, cost, linkBw, 6);
    createIsl(nodeC, nodeB, IslStatus.ACTIVE, IslStatus.ACTIVE, cost, linkBw, 6);
    createIsl(nodeB, nodeA, IslStatus.ACTIVE, IslStatus.ACTIVE, cost, linkBw, 5);
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(nodeA).destSwitch(nodeC).build();
    FlowPath forwardPath = FlowPath.builder().pathId(new PathId(UUID.randomUUID().toString())).srcSwitch(nodeA).destSwitch(nodeC).bandwidth(flowBandwidth).build();
    addPathSegment(forwardPath, nodeA, nodeB, 5, 5);
    addPathSegment(forwardPath, nodeB, nodeC, 6, 6);
    flow.setForwardPath(forwardPath);
    FlowPath reversePath = FlowPath.builder().pathId(new PathId(UUID.randomUUID().toString())).srcSwitch(nodeC).destSwitch(nodeA).bandwidth(flowBandwidth).build();
    addPathSegment(reversePath, nodeC, nodeB, 6, 6);
    addPathSegment(reversePath, nodeB, nodeA, 5, 5);
    flow.setReversePath(reversePath);
    flowRepository.add(flow);
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

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