Search in sources :

Example 11 with AvailableNetwork

use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method buildLinearNetworkWithPairLinks.

private AvailableNetwork buildLinearNetworkWithPairLinks() {
    /*
         * Topology:
         *
         * SW1===SW2===SW3
         *
         * All ISLs have equal cost.
         */
    AvailableNetwork network = new AvailableNetwork();
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 2, 10000);
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_2, 3, 4, 10000);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_3, 5, 6, 10000);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_3, 7, 8, 10000);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 12 with AvailableNetwork

use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method shouldReturnTheShortestPath.

@Test
public void shouldReturnTheShortestPath() throws UnroutableFlowException {
    AvailableNetwork network = buildTestNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_E, SWITCH_ID_F, WEIGHT_FUNCTION).getFoundPath();
    List<Edge> fpath = pairPath.getLeft();
    assertThat(fpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_E, fpath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_F, fpath.get(1).getDestSwitch().getSwitchId());
    List<Edge> rpath = pairPath.getRight();
    assertThat(rpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_F, rpath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_E, rpath.get(1).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 13 with AvailableNetwork

use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method buildTestNetwork.

private AvailableNetwork buildTestNetwork() {
    /*
         *   Topology:
         *
         *   D---C---F---B---E
         *   |   |   |   |   |
         *   |   +---A---+   |
         *   |      / \      |
         *   +-----+   +-----+
         */
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SWITCH_ID_A, SWITCH_ID_F, 7, 60, 0, 3, false, false);
    addLink(network, SWITCH_ID_A, SWITCH_ID_B, 5, 32, 10, 18, false, false);
    addLink(network, SWITCH_ID_A, SWITCH_ID_D, 2, 2, 10, 2, false, false);
    addLink(network, SWITCH_ID_A, SWITCH_ID_E, 6, 16, 10, 15, false, false);
    addLink(network, SWITCH_ID_A, SWITCH_ID_C, 1, 3, 40, 4, false, false);
    addLink(network, SWITCH_ID_D, SWITCH_ID_C, 1, 1, 100, 7, false, false);
    addLink(network, SWITCH_ID_D, SWITCH_ID_A, 2, 2, 10, 1, false, false);
    addLink(network, SWITCH_ID_C, SWITCH_ID_F, 6, 19, 10, 3, false, false);
    addLink(network, SWITCH_ID_C, SWITCH_ID_D, 1, 1, 100, 2, false, false);
    addLink(network, SWITCH_ID_C, SWITCH_ID_A, 3, 1, 100, 2, false, false);
    addLink(network, SWITCH_ID_E, SWITCH_ID_B, 52, 52, 10, 381, false, false);
    addLink(network, SWITCH_ID_E, SWITCH_ID_A, 16, 6, 10, 18, false, false);
    addLink(network, SWITCH_ID_B, SWITCH_ID_F, 48, 49, 10, 97, false, false);
    addLink(network, SWITCH_ID_B, SWITCH_ID_E, 52, 52, 10, 1021, false, false);
    addLink(network, SWITCH_ID_B, SWITCH_ID_A, 32, 5, 10, 16, false, false);
    addLink(network, SWITCH_ID_F, SWITCH_ID_B, 49, 48, 10, 0, false, false);
    addLink(network, SWITCH_ID_F, SWITCH_ID_C, 19, 6, 10, 3, false, false);
    addLink(network, SWITCH_ID_F, SWITCH_ID_A, 50, 7, 0, 3, false, false);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 14 with AvailableNetwork

use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method latencyStratUsesOnlyForwardLinksWeight.

/**
 * Check that we take into account ONLY forward-way links when calculating path using LATENCY strategy.
 */
@Test
public void latencyStratUsesOnlyForwardLinksWeight() throws UnroutableFlowException {
    // given 2 paths with costs: path1 forward 101, path1 reverse 99, path2 forward 100, path2 reverse 102
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 1, 101, 0, false, false);
    addLink(network, SWITCH_ID_2, SWITCH_ID_1, 1, 1, 99, 0, false, false);
    addLink(network, SWITCH_ID_1, SWITCH_ID_2, 2, 2, 100, 0, false, false);
    addLink(network, SWITCH_ID_2, SWITCH_ID_1, 2, 2, 102, 0, false, false);
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    // when: request a best-latency path
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_2, WEIGHT_FUNCTION).getFoundPath();
    // then: pick path2, because its forward cost is 100 which is less than forward 101 of path1
    // system ignores that path1 reverse cost is actually the best of all (99), since it only uses forward
    assertThat(pairPath.getLeft().get(0).getSrcPort(), equalTo(2));
    assertThat(pairPath.getRight().get(0).getSrcPort(), equalTo(2));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Test(org.junit.Test)

Example 15 with AvailableNetwork

use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method testForwardAndBackwardPathsEqualityEvenWhenReverseHasCheaperPath.

@Test
public void testForwardAndBackwardPathsEqualityEvenWhenReverseHasCheaperPath() throws UnroutableFlowException {
    // since our ISLs are bidirectional and cost may vary, we need to be sure that cost on reverse ISL won't be
    // taken into account during searching of reverse path.
    AvailableNetwork network = buildNetworkWithCostInReversePathBiggerThanForward();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    Pair<List<Edge>, List<Edge>> paths = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION).getFoundPath();
    List<SwitchId> forwardSwitchPath = getSwitchIdsFlowPath(paths.getLeft());
    List<SwitchId> backwardSwitchPath = Lists.reverse(getSwitchIdsFlowPath(paths.getRight()));
    assertEquals(forwardSwitchPath, backwardSwitchPath);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Test(org.junit.Test)

Aggregations

AvailableNetwork (org.openkilda.pce.impl.AvailableNetwork)43 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)24 List (java.util.List)23 Edge (org.openkilda.pce.model.Edge)13 SwitchId (org.openkilda.model.SwitchId)9 Flow (org.openkilda.model.Flow)7 IslImmutableView (org.openkilda.persistence.repositories.IslRepository.IslImmutableView)7 FindPathResult (org.openkilda.pce.model.FindPathResult)6 FlowPath (org.openkilda.model.FlowPath)3 PathId (org.openkilda.model.PathId)3 Collectors (java.util.stream.Collectors)2 Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 IntStream (java.util.stream.IntStream)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Pair (org.apache.commons.lang3.tuple.Pair)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1