Search in sources :

Example 1 with Edge

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());
}
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 2 with Edge

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();
}
Also used : Edge(org.openkilda.pce.model.Edge) PathSegment(org.openkilda.model.PathSegment) LinkedList(java.util.LinkedList)

Example 3 with Edge

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());
}
Also used : Node(org.openkilda.pce.model.Node) Edge(org.openkilda.pce.model.Edge)

Example 4 with Edge

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());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Edge(org.openkilda.pce.model.Edge) Test(org.junit.Test)

Example 5 with Edge

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);
}
Also used : Edge(org.openkilda.pce.model.Edge)

Aggregations

Edge (org.openkilda.pce.model.Edge)39 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Node (org.openkilda.pce.model.Node)15 AvailableNetwork (org.openkilda.pce.impl.AvailableNetwork)13 SwitchId (org.openkilda.model.SwitchId)7 WeightFunction (org.openkilda.pce.model.WeightFunction)7 HashSet (java.util.HashSet)5 PathSegment (org.openkilda.model.PathSegment)5 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)5 LinkedList (java.util.LinkedList)4 FindPathResult (org.openkilda.pce.model.FindPathResult)4 Collections.emptyList (java.util.Collections.emptyList)3 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 PathWeight (org.openkilda.pce.model.PathWeight)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2