Search in sources :

Example 6 with YSubFlow

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

the class YFlowReadService method getYFlowPaths.

/**
 * Gets y-flow paths.
 */
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
    return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
        Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
        Set<FlowPath> mainPaths = new HashSet<>();
        Set<FlowPath> protectedPaths = new HashSet<>();
        for (YSubFlow subFlow : subFlows) {
            Flow flow = subFlow.getFlow();
            mainPaths.add(flow.getForwardPath());
            if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
                protectedPaths.add(flow.getProtectedForwardPath());
            }
        }
        List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
        PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
        PathInfoData sharedProtectedPath;
        // At least 2 paths required to calculate Y-point.
        if (protectedPaths.size() < 2) {
            sharedProtectedPath = new PathInfoData();
        } else {
            List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
            sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
        }
        List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
    });
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) YFlowDto(org.openkilda.messaging.command.yflow.YFlowDto) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) HashSet(java.util.HashSet) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YSubFlow(org.openkilda.model.YSubFlow) ErrorType(org.openkilda.messaging.error.ErrorType) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) YFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.YFlowMapper) Objects(java.util.Objects) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) Collections(java.util.Collections) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) PathSegment(org.openkilda.model.PathSegment) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse)

Example 7 with YSubFlow

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

the class OnSubFlowAllocatedAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    String subFlowId = context.getSubFlowId();
    if (!stateMachine.isUpdatingSubFlow(subFlowId)) {
        throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
    }
    String yFlowId = stateMachine.getYFlowId();
    stateMachine.saveActionToHistory("Updating a sub-flow", format("Allocated resources for sub-flow %s of y-flow %s", subFlowId, yFlowId));
    stateMachine.addAllocatedSubFlow(subFlowId);
    SubFlowDto subFlowDto = stateMachine.getTargetFlow().getSubFlows().stream().filter(f -> f.getFlowId().equals(subFlowId)).findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Can't find definition of updated sub-flow %s", subFlowId)));
    SubFlowSharedEndpointEncapsulation sharedEndpoint = subFlowDto.getSharedEndpoint();
    FlowEndpoint endpoint = subFlowDto.getEndpoint();
    log.debug("Start updating sub-flow references from {} to y-flow {}", subFlowId, stateMachine.getYFlowId());
    YFlow result = transactionManager.doInTransaction(() -> {
        YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found", yFlowId)));
        Flow flow = flowRepository.findById(subFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Flow %s not found", subFlowId)));
        YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpoint.getVlanId()).sharedEndpointInnerVlan(sharedEndpoint.getInnerVlanId()).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
        yFlow.updateSubFlow(subFlow);
        return yFlow;
    });
    if (stateMachine.getAllocatedSubFlows().size() == stateMachine.getSubFlows().size()) {
        return Optional.of(buildResponseMessage(result, stateMachine.getCommandContext()));
    } else {
        return Optional.empty();
    }
}
Also used : YFlow(org.openkilda.model.YFlow) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 8 with YSubFlow

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

the class YFlowMapper method toSubFlowDto.

/**
 * Map {@link YSubFlow} to {@link SubFlowDto}.
 */
public SubFlowDto toSubFlowDto(YSubFlow subFlow) {
    SubFlowSharedEndpointEncapsulation sharedEndpoint = SubFlowSharedEndpointEncapsulation.builder().vlanId(subFlow.getSharedEndpointVlan()).innerVlanId(subFlow.getSharedEndpointInnerVlan()).build();
    FlowEndpoint endpoint = FlowEndpoint.builder().switchId(subFlow.getEndpointSwitchId()).portNumber(subFlow.getEndpointPort()).outerVlanId(subFlow.getEndpointVlan()).innerVlanId(subFlow.getEndpointInnerVlan()).build();
    Optional<Flow> flow = Optional.ofNullable(subFlow.getFlow());
    return SubFlowDto.builder().flowId(subFlow.getSubFlowId()).endpoint(endpoint).sharedEndpoint(sharedEndpoint).status(flow.map(Flow::getStatus).orElse(null)).description(flow.map(Flow::getDescription).orElse(null)).timeCreate(flow.map(Flow::getTimeCreate).orElse(null)).timeUpdate(flow.map(Flow::getTimeModify).orElse(null)).build();
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 9 with YSubFlow

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

the class FlowValidator method checkDiverseFlow.

@VisibleForTesting
void checkDiverseFlow(RequestedFlow targetFlow) throws InvalidFlowException {
    if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
        throw new InvalidFlowException("Couldn't add one-switch flow into diverse group", ErrorType.PARAMETERS_INVALID);
    }
    Flow diverseFlow = flowRepository.findById(targetFlow.getDiverseFlowId()).orElse(null);
    if (diverseFlow == null) {
        YFlow diverseYFlow = yFlowRepository.findById(targetFlow.getDiverseFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", targetFlow.getDiverseFlowId()), ErrorType.PARAMETERS_INVALID));
        diverseFlow = diverseYFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow for diverse y-flow id %s", targetFlow.getDiverseFlowId()), ErrorType.INTERNAL_ERROR));
    }
    if (StringUtils.isNotBlank(diverseFlow.getAffinityGroupId())) {
        String diverseFlowId = diverseFlow.getAffinityGroupId();
        diverseFlow = flowRepository.findById(diverseFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", diverseFlowId), ErrorType.PARAMETERS_INVALID));
        Collection<String> affinityFlowIds = flowRepository.findFlowsIdByAffinityGroupId(diverseFlow.getAffinityGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
        if (affinityFlowIds.contains(targetFlow.getAffinityFlowId())) {
            throw new InvalidFlowException("Couldn't create diverse group with flow in the same affinity group", ErrorType.PARAMETERS_INVALID);
        }
    }
    if (diverseFlow.isOneSwitchFlow()) {
        throw new InvalidFlowException("Couldn't create diverse group with one-switch flow", ErrorType.PARAMETERS_INVALID);
    }
}
Also used : YFlow(org.openkilda.model.YFlow) Getter(lombok.Getter) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccessLevel(lombok.AccessLevel) Flow(org.openkilda.model.Flow) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) PersistenceManager(org.openkilda.persistence.PersistenceManager) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) FlowMirrorPointsRepository(org.openkilda.persistence.repositories.FlowMirrorPointsRepository) YSubFlow(org.openkilda.model.YSubFlow) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) ErrorType(org.openkilda.messaging.error.ErrorType) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) RequestedFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.RequestedFlowMapper) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with YSubFlow

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

the class YFlowRerouteServiceTest method verifyYFlowStatus.

protected YFlow verifyYFlowStatus(String yFlowId, FlowStatus expectedStatus, FlowStatus expectedFirstSubFlowStatus, FlowStatus expectedSecondSubFlowStatus) {
    YFlow flow = getYFlow(yFlowId);
    assertEquals(expectedStatus, flow.getStatus());
    Set<FlowStatus> expectedSubFlowStatuses = Stream.of(expectedFirstSubFlowStatus, expectedSecondSubFlowStatus).collect(Collectors.toSet());
    Set<FlowStatus> actualSubFlowStatuses = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getStatus).collect(Collectors.toSet());
    assertEquals(expectedSubFlowStatuses, actualSubFlowStatuses);
    return flow;
}
Also used : YFlow(org.openkilda.model.YFlow) FlowStatus(org.openkilda.model.FlowStatus) YSubFlow(org.openkilda.model.YSubFlow)

Aggregations

YSubFlow (org.openkilda.model.YSubFlow)26 YFlow (org.openkilda.model.YFlow)24 Flow (org.openkilda.model.Flow)18 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)11 SwitchId (org.openkilda.model.SwitchId)7 ArrayList (java.util.ArrayList)6 FlowEndpoint (org.openkilda.model.FlowEndpoint)6 FlowPath (org.openkilda.model.FlowPath)5 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 ErrorType (org.openkilda.messaging.error.ErrorType)4 PathSegment (org.openkilda.model.PathSegment)4 PersistenceManager (org.openkilda.persistence.PersistenceManager)4 CommandContext (org.openkilda.wfm.CommandContext)4 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 SubFlowDto (org.openkilda.messaging.command.yflow.SubFlowDto)3 SubFlowSharedEndpointEncapsulation (org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation)3 String.format (java.lang.String.format)2