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();
}
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());
}
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;
}
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);
});
}
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());
}
Aggregations