use of org.openkilda.pce.model.Edge 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.pce.model.Edge in project open-kilda by telstra.
the class InMemoryPathComputer method convertToPath.
private Path convertToPath(SwitchId srcSwitchId, SwitchId dstSwitchId, List<Edge> edges) {
List<Path.Segment> segments = new LinkedList<>();
long latency = 0L;
long minAvailableBandwidth = Long.MAX_VALUE;
for (Edge edge : edges) {
latency += edge.getLatency();
minAvailableBandwidth = Math.min(minAvailableBandwidth, edge.getAvailableBandwidth());
segments.add(convertToSegment(edge));
}
return Path.builder().srcSwitchId(srcSwitchId).destSwitchId(dstSwitchId).segments(segments).latency(latency).minAvailableBandwidth(minAvailableBandwidth).build();
}
use of org.openkilda.pce.model.Edge in project open-kilda by telstra.
the class AvailableNetworkFactoryTest method assertAvailableNetworkIsCorrect.
private static void assertAvailableNetworkIsCorrect(IslImmutableView isl, AvailableNetwork availableNetwork) {
Node src = availableNetwork.getSwitch(isl.getSrcSwitchId());
assertNotNull(src);
assertEquals(1, src.getOutgoingLinks().size());
Edge edge = src.getOutgoingLinks().iterator().next();
assertEquals(isl.getSrcSwitchId(), edge.getSrcSwitch().getSwitchId());
assertEquals(isl.getSrcPort(), edge.getSrcPort());
assertEquals(isl.getDestSwitchId(), edge.getDestSwitch().getSwitchId());
assertEquals(isl.getDestPort(), edge.getDestPort());
assertEquals(isl.getCost(), edge.getCost());
assertEquals(isl.getLatency(), edge.getLatency());
assertEquals(isl.getAvailableBandwidth(), edge.getAvailableBandwidth());
Node dst = availableNetwork.getSwitch(isl.getDestSwitchId());
assertNotNull(dst);
assertEquals(1, dst.getIncomingLinks().size());
}
use of org.openkilda.pce.model.Edge in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method shouldChooseDeeperOverCheaperMaxWeightStrategy.
@Test
public void shouldChooseDeeperOverCheaperMaxWeightStrategy() throws UnroutableFlowException {
AvailableNetwork network = buildLongAndExpensivePathsNetwork();
BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(4);
Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_3, WEIGHT_FUNCTION, Long.MAX_VALUE, Long.MAX_VALUE).getFoundPath();
List<Edge> fpath = pairPath.getLeft();
assertThat(fpath, Matchers.hasSize(4));
assertEquals(SWITCH_ID_5, fpath.get(3).getSrcSwitch().getSwitchId());
List<Edge> rpath = pairPath.getRight();
assertThat(rpath, Matchers.hasSize(4));
assertEquals(SWITCH_ID_5, rpath.get(0).getDestSwitch().getSwitchId());
}
use of org.openkilda.pce.model.Edge in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method addLink.
private void addLink(AvailableNetwork network, SwitchId srcDpid, SwitchId dstDpid, int srcPort, int dstPort, int cost, int latency, boolean isUnstable, boolean isUnderMaintenance) {
Edge edge = Edge.builder().srcSwitch(network.getOrAddNode(srcDpid, null)).srcPort(srcPort).destSwitch(network.getOrAddNode(dstDpid, null)).destPort(dstPort).latency(latency).cost(cost).availableBandwidth(500000).underMaintenance(isUnderMaintenance).unstable(isUnstable).build();
network.addEdge(edge);
}
Aggregations