Search in sources :

Example 1 with PathComputationStrategy

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

the class FlowMapper method map.

/**
 * Convert {@link FlowDto} to {@link Flow}.
 * If encapsulation type and/or path computation strategy is not provided then values from KildaConfiguration
 * will be used.
 */
public Flow map(FlowDto flow, Supplier<KildaConfiguration> kildaConfiguration) {
    Switch srcSwitch = Switch.builder().switchId(flow.getSourceSwitch()).build();
    Switch destSwitch = Switch.builder().switchId(flow.getDestinationSwitch()).build();
    return Flow.builder().flowId(flow.getFlowId()).srcSwitch(srcSwitch).destSwitch(destSwitch).srcPort(flow.getSourcePort()).destPort(flow.getDestinationPort()).srcVlan(flow.getSourceVlan()).destVlan(flow.getDestinationVlan()).status(map(flow.getState())).statusInfo(flow.getStatusInfo()).description(flow.getDescription()).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).periodicPings(Boolean.TRUE.equals(flow.getPeriodicPings())).allocateProtectedPath(flow.isAllocateProtectedPath()).encapsulationType(Optional.ofNullable(flow.getEncapsulationType()).map(encapsulationType -> FlowEncapsulationType.valueOf(encapsulationType.name())).orElse(kildaConfiguration.get().getFlowEncapsulationType())).pathComputationStrategy(Optional.ofNullable(flow.getPathComputationStrategy()).map(pathComputationStrategy -> PathComputationStrategy.valueOf(pathComputationStrategy.name())).orElse(kildaConfiguration.get().getPathComputationStrategy())).maxLatency(flow.getMaxLatency()).priority(flow.getPriority()).pinned(flow.isPinned()).detectConnectedDevices(DetectConnectedDevicesMapper.INSTANCE.map(flow.getDetectConnectedDevices())).build();
}
Also used : FlowStatusDetails(org.openkilda.messaging.payload.flow.FlowStatusDetails) FlowStats(org.openkilda.model.FlowStats) Mapping(org.mapstruct.Mapping) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) Supplier(java.util.function.Supplier) FlowPathStatus(org.openkilda.model.FlowPathStatus) Flow(org.openkilda.model.Flow) Mapper(org.mapstruct.Mapper) SwapFlowDto(org.openkilda.messaging.model.SwapFlowDto) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Mappers(org.mapstruct.factory.Mappers) PathId(org.openkilda.model.PathId) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) KildaConfiguration(org.openkilda.model.KildaConfiguration) Set(java.util.Set) FlowDto(org.openkilda.messaging.model.FlowDto) UUID(java.util.UUID) Instant(java.time.Instant) MeterId(org.openkilda.model.MeterId) List(java.util.List) FlowPairDto(org.openkilda.messaging.model.FlowPairDto) MirrorPointStatusDto(org.openkilda.messaging.model.MirrorPointStatusDto) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) FlowState(org.openkilda.messaging.payload.flow.FlowState) Switch(org.openkilda.model.Switch)

Example 2 with PathComputationStrategy

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

the class InMemoryPathComputer method getNPaths.

@Override
public List<Path> getNPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, int count, FlowEncapsulationType flowEncapsulationType, PathComputationStrategy pathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, UnroutableFlowException {
    final long maxLatencyNs = maxLatency != null ? maxLatency.toNanos() : 0;
    final long maxLatencyTier2Ns = maxLatencyTier2 != null ? maxLatencyTier2.toNanos() : 0;
    Flow flow = Flow.builder().flowId(// just any id, as not used.
    "").srcSwitch(Switch.builder().switchId(srcSwitchId).build()).destSwitch(Switch.builder().switchId(dstSwitchId).build()).ignoreBandwidth(false).encapsulationType(flowEncapsulationType).bandwidth(// to get ISLs with non zero available bandwidth
    1).maxLatency(maxLatencyNs).maxLatencyTier2(maxLatencyTier2Ns).build();
    AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
    if (MAX_LATENCY.equals(pathComputationStrategy) && (flow.getMaxLatency() == null || flow.getMaxLatency() == 0)) {
        pathComputationStrategy = LATENCY;
    }
    List<List<Edge>> paths;
    switch(pathComputationStrategy) {
        case COST:
        case LATENCY:
        case COST_AND_AVAILABLE_BANDWIDTH:
            paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy));
            break;
        case MAX_LATENCY:
            paths = pathFinder.findNPathsBetweenSwitches(availableNetwork, srcSwitchId, dstSwitchId, count, getWeightFunctionByStrategy(pathComputationStrategy), maxLatencyNs, maxLatencyTier2Ns);
            break;
        default:
            throw new UnsupportedOperationException(String.format("Unsupported strategy type %s", pathComputationStrategy));
    }
    Comparator<Path> comparator;
    if (pathComputationStrategy == LATENCY || pathComputationStrategy == MAX_LATENCY) {
        comparator = Comparator.comparing(Path::getLatency).thenComparing(Comparator.comparing(Path::getMinAvailableBandwidth).reversed());
    } else {
        comparator = Comparator.comparing(Path::getMinAvailableBandwidth).reversed().thenComparing(Path::getLatency);
    }
    return paths.stream().map(edges -> convertToPath(srcSwitchId, dstSwitchId, edges)).sorted(comparator).limit(count).collect(Collectors.toList());
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) RecoverableException(org.openkilda.pce.exception.RecoverableException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Edge(org.openkilda.pce.model.Edge) Flow(org.openkilda.model.Flow) AvailableNetworkFactory(org.openkilda.pce.AvailableNetworkFactory) Duration(java.time.Duration) PathComputerConfig(org.openkilda.pce.PathComputerConfig) LinkedList(java.util.LinkedList) PathId(org.openkilda.model.PathId) Path(org.openkilda.pce.Path) PathFinder(org.openkilda.pce.finder.PathFinder) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathWeight(org.openkilda.pce.model.PathWeight) Switch(org.openkilda.model.Switch) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) WeightFunction(org.openkilda.pce.model.WeightFunction) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FindPathResult(org.openkilda.pce.model.FindPathResult) PathComputer(org.openkilda.pce.PathComputer) Optional(java.util.Optional) GetPathsResult(org.openkilda.pce.GetPathsResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Flow(org.openkilda.model.Flow)

Example 3 with PathComputationStrategy

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

the class RerouteQueueService method compareAvailableBandwidth.

private int compareAvailableBandwidth(FlowThrottlingData throttlingDataA, FlowThrottlingData throttlingDataB) {
    PathComputationStrategy pathComputationStrategyA = throttlingDataA.getPathComputationStrategy();
    PathComputationStrategy pathComputationStrategyB = throttlingDataB.getPathComputationStrategy();
    long bandwidthA = throttlingDataA.getBandwidth();
    long bandwidthB = throttlingDataB.getBandwidth();
    if (pathComputationStrategyA == COST_AND_AVAILABLE_BANDWIDTH && pathComputationStrategyB == COST_AND_AVAILABLE_BANDWIDTH) {
        if (bandwidthA != bandwidthB) {
            return Long.compare(bandwidthB, bandwidthA);
        }
    } else {
        if (pathComputationStrategyA == COST_AND_AVAILABLE_BANDWIDTH) {
            return 1;
        }
        if (pathComputationStrategyB == COST_AND_AVAILABLE_BANDWIDTH) {
            return -1;
        }
    }
    return 0;
}
Also used : PathComputationStrategy(org.openkilda.model.PathComputationStrategy)

Example 4 with PathComputationStrategy

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

the class NetworkServiceImpl method getPaths.

@Override
public CompletableFuture<PathsDto> getPaths(SwitchId srcSwitch, SwitchId dstSwitch, FlowEncapsulationType encapsulationType, PathComputationStrategy pathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) {
    String correlationId = RequestCorrelationId.getId();
    if (PathComputationStrategy.MAX_LATENCY.equals(pathComputationStrategy) && maxLatency == null) {
        throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID, "Missed max_latency parameter.", "MAX_LATENCY path computation strategy requires non null " + "max_latency parameter. If max_latency will be equal to 0 LATENCY strategy will be used instead " + "of MAX_LATENCY.");
    }
    GetPathsRequest request = new GetPathsRequest(srcSwitch, dstSwitch, encapsulationType, pathComputationStrategy, maxLatency, maxLatencyTier2);
    CommandMessage message = new CommandMessage(request, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGetChunked(nbworkerTopic, message).thenApply(paths -> {
        List<PathDto> pathsDtoList = paths.stream().map(PathsInfoData.class::cast).map(p -> pathMapper.mapToPath(p.getPath())).collect(Collectors.toList());
        return new PathsDto(pathsDtoList);
    });
}
Also used : FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ErrorType(org.openkilda.messaging.error.ErrorType) Autowired(org.springframework.beans.factory.annotation.Autowired) NetworkService(org.openkilda.northbound.service.NetworkService) CompletableFuture(java.util.concurrent.CompletableFuture) RequestCorrelationId(org.openkilda.northbound.utils.RequestCorrelationId) Collectors(java.util.stream.Collectors) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) PathMapper(org.openkilda.northbound.converter.PathMapper) MessageException(org.openkilda.messaging.error.MessageException) Value(org.springframework.beans.factory.annotation.Value) CommandMessage(org.openkilda.messaging.command.CommandMessage) List(java.util.List) PathDto(org.openkilda.messaging.payload.network.PathDto) SwitchId(org.openkilda.model.SwitchId) Service(org.springframework.stereotype.Service) MessagingChannel(org.openkilda.northbound.messaging.MessagingChannel) Duration(java.time.Duration) GetPathsRequest(org.openkilda.messaging.nbtopology.request.GetPathsRequest) PathsDto(org.openkilda.messaging.payload.network.PathsDto) PathDto(org.openkilda.messaging.payload.network.PathDto) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) MessageException(org.openkilda.messaging.error.MessageException) PathsDto(org.openkilda.messaging.payload.network.PathsDto) GetPathsRequest(org.openkilda.messaging.nbtopology.request.GetPathsRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 5 with PathComputationStrategy

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

the class PathsService method getPaths.

/**
 * Get paths.
 */
public List<PathsInfoData> getPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException {
    if (Objects.equals(srcSwitchId, dstSwitchId)) {
        throw new IllegalArgumentException(String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId));
    }
    if (!switchRepository.exists(srcSwitchId)) {
        throw new SwitchNotFoundException(srcSwitchId);
    }
    if (!switchRepository.exists(dstSwitchId)) {
        throw new SwitchNotFoundException(dstSwitchId);
    }
    KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault();
    FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType).orElse(kildaConfiguration.getFlowEncapsulationType());
    SwitchProperties srcProperties = switchPropertiesRepository.findBySwitchId(srcSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(srcSwitchId));
    if (!srcProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
        throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", srcSwitchId, flowEncapsulationType, srcProperties.getSupportedTransitEncapsulation()));
    }
    SwitchProperties dstProperties = switchPropertiesRepository.findBySwitchId(dstSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(dstSwitchId));
    if (!dstProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
        throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", dstSwitchId, requestEncapsulationType, dstProperties.getSupportedTransitEncapsulation()));
    }
    PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy).orElse(kildaConfiguration.getPathComputationStrategy());
    List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy, maxLatency, maxLatencyTier2);
    return flowPaths.stream().map(PathMapper.INSTANCE::map).map(path -> PathsInfoData.builder().path(path).build()).collect(Collectors.toList());
}
Also used : Path(org.openkilda.pce.Path) KildaConfigurationRepository(org.openkilda.persistence.repositories.KildaConfigurationRepository) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) RecoverableException(org.openkilda.pce.exception.RecoverableException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) AvailableNetworkFactory(org.openkilda.pce.AvailableNetworkFactory) Duration(java.time.Duration) PathComputerConfig(org.openkilda.pce.PathComputerConfig) Path(org.openkilda.pce.Path) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) KildaConfiguration(org.openkilda.model.KildaConfiguration) Collectors(java.util.stream.Collectors) PathComputerFactory(org.openkilda.pce.PathComputerFactory) Objects(java.util.Objects) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) PathComputer(org.openkilda.pce.PathComputer) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathMapper(org.openkilda.wfm.share.mappers.PathMapper) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) SwitchProperties(org.openkilda.model.SwitchProperties) KildaConfiguration(org.openkilda.model.KildaConfiguration)

Aggregations

PathComputationStrategy (org.openkilda.model.PathComputationStrategy)6 List (java.util.List)4 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)4 SwitchId (org.openkilda.model.SwitchId)4 Duration (java.time.Duration)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Flow (org.openkilda.model.Flow)3 Objects (java.util.Objects)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 PathsInfoData (org.openkilda.messaging.info.network.PathsInfoData)2 FlowPath (org.openkilda.model.FlowPath)2 KildaConfiguration (org.openkilda.model.KildaConfiguration)2 PathId (org.openkilda.model.PathId)2 Switch (org.openkilda.model.Switch)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1