Search in sources :

Example 1 with FlowPath

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

the class BaseResourceAllocationAction method createFlowPathPair.

protected FlowPathPair createFlowPathPair(String flowId, FlowResources flowResources, GetPathsResult pathPair, boolean forceToIgnoreBandwidth, String sharedBandwidthGroupId) {
    FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
    return transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(flowId);
        updateSwitchRelatedFlowProperties(flow);
        Path forward = pathPair.getForward();
        List<PathSegment> forwardSegments = pathSegmentRepository.findByPathId(flowResources.getForward().getPathId());
        FlowPath newForwardPath = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), forward.getLatency(), forward.getSrcSwitchId(), forward.getDestSwitchId(), forwardSegments, cookieBuilder.direction(FlowPathDirection.FORWARD).build(), forceToIgnoreBandwidth, sharedBandwidthGroupId);
        newForwardPath.setStatus(FlowPathStatus.IN_PROGRESS);
        Path reverse = pathPair.getReverse();
        List<PathSegment> reverseSegments = pathSegmentRepository.findByPathId(flowResources.getReverse().getPathId());
        FlowPath newReversePath = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), reverse.getLatency(), reverse.getSrcSwitchId(), reverse.getDestSwitchId(), reverseSegments, cookieBuilder.direction(FlowPathDirection.REVERSE).build(), forceToIgnoreBandwidth, sharedBandwidthGroupId);
        newReversePath.setStatus(FlowPathStatus.IN_PROGRESS);
        log.debug("Persisting the paths {}/{}", newForwardPath, newReversePath);
        flowPathRepository.add(newForwardPath);
        flowPathRepository.add(newReversePath);
        flow.addPaths(newForwardPath, newReversePath);
        return FlowPathPair.builder().forward(newForwardPath).reverse(newReversePath).build();
    });
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) FlowSegmentCookieBuilder(org.openkilda.model.cookie.FlowSegmentCookie.FlowSegmentCookieBuilder) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 2 with FlowPath

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

the class YFlowRuleManagerProcessingAction method buildYFlowSpeakerData.

private Map<SwitchId, List<SpeakerData>> buildYFlowSpeakerData(YFlow yFlow) {
    List<FlowPath> flowPaths = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getPaths).flatMap(Collection::stream).collect(toList());
    Set<SwitchId> switchIds = Sets.newHashSet(yFlow.getSharedEndpoint().getSwitchId(), yFlow.getYPoint(), yFlow.getProtectedPathYPoint());
    Set<PathId> pathIds = flowPaths.stream().map(FlowPath::getPathId).collect(Collectors.toSet());
    DataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(switchIds).pathIds(pathIds).build();
    return ruleManager.buildRulesForYFlow(flowPaths, dataAdapter).stream().collect(Collectors.groupingBy(SpeakerData::getSwitchId, Collectors.mapping(Function.identity(), toList())));
}
Also used : PathId(org.openkilda.model.PathId) DataAdapter(org.openkilda.rulemanager.DataAdapter) PersistenceDataAdapter(org.openkilda.rulemanager.adapter.PersistenceDataAdapter) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 3 with FlowPath

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

the class CompleteFlowPathRemovalAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    Flow flow = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(stateMachine.getFlowId());
        Stream.of(foundFlow.getForwardPath(), foundFlow.getReversePath()).map(FlowPath::getFlowMirrorPointsSet).flatMap(Collection::stream).forEach(mirrorPoints -> {
            Set<Long> cookies = new HashSet<>();
            mirrorPoints.getMirrorPaths().forEach(mirrorPath -> {
                cookies.add(mirrorPath.getCookie().getFlowEffectiveId());
                flowMirrorPathRepository.remove(mirrorPath);
            });
            stateMachine.getFlowMirrorPathResources().add(FlowMirrorPathResources.builder().flowPathId(mirrorPoints.getFlowPathId()).mirrorSwitchId(mirrorPoints.getMirrorSwitchId()).unmaskedCookies(cookies).build());
            flowMirrorPointsRepository.remove(mirrorPoints);
        });
        return foundFlow;
    });
    // Iterate to remove each path in a dedicated transaction.
    flow.getPathIds().forEach(pathId -> {
        Optional<FlowPath> deletedPath = flowPathRepository.remove(pathId);
        deletedPath.ifPresent(path -> {
            updateIslsForFlowPath(path);
            saveRemovalActionWithDumpToHistory(stateMachine, flow, new FlowPathPair(path, path));
        });
    });
}
Also used : FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) HashSet(java.util.HashSet) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair)

Example 4 with FlowPath

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

the class HandleNotRemovedPathsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    FlowPath[] paths = flow.getPaths().stream().filter(Objects::nonNull).toArray(FlowPath[]::new);
    stateMachine.saveErrorToHistory("Failed to remove paths", format("Failed to remove paths: \"%s\"", Arrays.stream(paths).map(FlowPath::getPathId).map(PathId::toString).collect(Collectors.joining("\", \""))));
}
Also used : FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 5 with FlowPath

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

the class ResourcesAllocationAction method allocateProtectedPath.

private void allocateProtectedPath(FlowCreateFsm stateMachine) throws UnroutableFlowException, RecoverableException, ResourceAllocationException, FlowNotFoundException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlow = getFlow(flowId);
    if (!tmpFlow.isAllocateProtectedPath()) {
        return;
    }
    tmpFlow.setDiverseGroupId(getFlowDiverseGroupFromContext(flowId).orElseThrow(() -> new FlowNotFoundException(flowId)));
    GetPathsResult protectedPath = pathComputer.getPath(tmpFlow);
    stateMachine.setBackUpProtectedPathComputationWayUsed(protectedPath.isBackUpPathComputationWayUsed());
    boolean overlappingProtectedPathFound = flowPathBuilder.arePathsOverlapped(protectedPath.getForward(), tmpFlow.getForwardPath()) || flowPathBuilder.arePathsOverlapped(protectedPath.getReverse(), tmpFlow.getReversePath());
    if (overlappingProtectedPathFound) {
        log.info("Couldn't find non overlapping protected path. Result flow state: {}", tmpFlow);
        throw new UnroutableFlowException("Couldn't find non overlapping protected path", tmpFlow.getFlowId());
    }
    log.debug("Creating the protected path {} for flow {}", protectedPath, tmpFlow);
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(flowId);
        FlowResources flowResources = resourcesManager.allocateFlowResources(flow);
        final FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
        FlowPath forward = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), protectedPath.getForward(), cookieBuilder.direction(FlowPathDirection.FORWARD).build(), false, stateMachine.getSharedBandwidthGroupId());
        forward.setStatus(FlowPathStatus.IN_PROGRESS);
        flowPathRepository.add(forward);
        flow.setProtectedForwardPath(forward);
        FlowPath reverse = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), protectedPath.getReverse(), cookieBuilder.direction(FlowPathDirection.REVERSE).build(), false, stateMachine.getSharedBandwidthGroupId());
        reverse.setStatus(FlowPathStatus.IN_PROGRESS);
        flowPathRepository.add(reverse);
        flow.setProtectedReversePath(reverse);
        updateIslsForFlowPath(forward.getPathId());
        updateIslsForFlowPath(reverse.getPathId());
        stateMachine.setProtectedForwardPathId(forward.getPathId());
        stateMachine.setProtectedReversePathId(reverse.getPathId());
        log.debug("Allocated resources for the flow {}: {}", flow.getFlowId(), flowResources);
        stateMachine.getFlowResources().add(flowResources);
    });
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FlowSegmentCookieBuilder(org.openkilda.model.cookie.FlowSegmentCookie.FlowSegmentCookieBuilder) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) YFlow(org.openkilda.model.YFlow) GetPathsResult(org.openkilda.pce.GetPathsResult)

Aggregations

FlowPath (org.openkilda.model.FlowPath)229 Flow (org.openkilda.model.Flow)128 Test (org.junit.Test)108 PathId (org.openkilda.model.PathId)65 PathSegment (org.openkilda.model.PathSegment)42 SwitchId (org.openkilda.model.SwitchId)40 ArrayList (java.util.ArrayList)39 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)33 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)29 Switch (org.openkilda.model.Switch)28 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)27 SpeakerData (org.openkilda.rulemanager.SpeakerData)27 Action (org.openkilda.rulemanager.action.Action)26 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)26 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)26 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)26 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)26 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)26 MeterId (org.openkilda.model.MeterId)20 YFlow (org.openkilda.model.YFlow)19