Search in sources :

Example 26 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method findPathThrowMoreExpensiveWayMaxLatencyStrategy.

private FindPathResult findPathThrowMoreExpensiveWayMaxLatencyStrategy(long maxWeight, long backUpMaxWeight) throws UnroutableFlowException {
    // Reverse way is more expansive then forward, so we must choose this path
    // and the sequence of switches must match the forward path.
    AvailableNetwork network = buildNetworkWithCostInReversePathBiggerThanForward();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    FindPathResult pathResult = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION, maxWeight, backUpMaxWeight);
    Pair<List<Edge>, List<Edge>> paths = pathResult.getFoundPath();
    List<Edge> fpath = paths.getLeft();
    assertThat(fpath, Matchers.hasSize(3));
    assertEquals(SWITCH_ID_1, fpath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_3, fpath.get(2).getSrcSwitch().getSwitchId());
    List<Edge> rpath = paths.getRight();
    assertThat(rpath, Matchers.hasSize(3));
    assertEquals(SWITCH_ID_5, fpath.get(2).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_3, rpath.get(0).getDestSwitch().getSwitchId());
    return pathResult;
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Edge(org.openkilda.pce.model.Edge)

Example 27 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldBuildPathDependsOnIslConfig.

@Test
public void shouldBuildPathDependsOnIslConfig() throws UnroutableFlowException {
    // Network without unstable and under maintenance links.
    AvailableNetwork network = buildTestNetworkForVerifyIslConfig(false, false);
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_A, SWITCH_ID_B, WEIGHT_FUNCTION).getFoundPath();
    List<Edge> forwardPath = pairPath.getLeft();
    assertThat(forwardPath, Matchers.hasSize(1));
    assertEquals(SWITCH_ID_A, forwardPath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_B, forwardPath.get(0).getDestSwitch().getSwitchId());
    List<Edge> reversePath = pairPath.getRight();
    assertThat(reversePath, Matchers.hasSize(1));
    assertEquals(SWITCH_ID_B, reversePath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_A, reversePath.get(0).getDestSwitch().getSwitchId());
    // Network where shortest path has under maintenance link.
    network = buildTestNetworkForVerifyIslConfig(true, false);
    pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_A, SWITCH_ID_B, WEIGHT_FUNCTION).getFoundPath();
    forwardPath = pairPath.getLeft();
    assertThat(forwardPath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_A, forwardPath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_C, forwardPath.get(0).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_C, forwardPath.get(1).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_B, forwardPath.get(1).getDestSwitch().getSwitchId());
    reversePath = pairPath.getRight();
    assertThat(reversePath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_B, reversePath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_C, reversePath.get(0).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_C, reversePath.get(1).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_A, reversePath.get(1).getDestSwitch().getSwitchId());
    // Network where shortest path has under maintenance link and another short path has unstable link.
    network = buildTestNetworkForVerifyIslConfig(true, true);
    pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_A, SWITCH_ID_B, WEIGHT_FUNCTION).getFoundPath();
    forwardPath = pairPath.getLeft();
    assertThat(forwardPath, Matchers.hasSize(3));
    assertEquals(SWITCH_ID_A, forwardPath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_D, forwardPath.get(0).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_D, forwardPath.get(1).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_E, forwardPath.get(1).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_E, forwardPath.get(2).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_B, forwardPath.get(2).getDestSwitch().getSwitchId());
    reversePath = pairPath.getRight();
    assertThat(reversePath, Matchers.hasSize(3));
    assertEquals(SWITCH_ID_B, reversePath.get(0).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_E, reversePath.get(0).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_E, reversePath.get(1).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_D, reversePath.get(1).getDestSwitch().getSwitchId());
    assertEquals(SWITCH_ID_D, reversePath.get(2).getSrcSwitch().getSwitchId());
    assertEquals(SWITCH_ID_A, reversePath.get(2).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 28 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldChooseDeeperOverExpensive.

@Test
public void shouldChooseDeeperOverExpensive() throws UnroutableFlowException {
    AvailableNetwork network = buildLongAndExpensivePathsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(4);
    Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_4, WEIGHT_FUNCTION).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 29 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method buildTestNetworkForTestYensAlgorithm.

private AvailableNetwork buildTestNetworkForTestYensAlgorithm() {
    /*
         *   Topology:
         *
         *   A--B--C
         *    \ | /|\
         *     \|/ | \
         *      D--E--F
         */
    AvailableNetwork network = new AvailableNetwork();
    addBidirectionalLink(network, SWITCH_ID_A, SWITCH_ID_B, 1, 1, 3);
    addBidirectionalLink(network, SWITCH_ID_A, SWITCH_ID_D, 2, 1, 2);
    addBidirectionalLink(network, SWITCH_ID_B, SWITCH_ID_C, 2, 1, 4);
    addBidirectionalLink(network, SWITCH_ID_B, SWITCH_ID_D, 3, 2, 1);
    addBidirectionalLink(network, SWITCH_ID_C, SWITCH_ID_D, 2, 3, 2);
    addBidirectionalLink(network, SWITCH_ID_C, SWITCH_ID_E, 3, 1, 2);
    addBidirectionalLink(network, SWITCH_ID_C, SWITCH_ID_F, 4, 1, 1);
    addBidirectionalLink(network, SWITCH_ID_D, SWITCH_ID_E, 4, 2, 3);
    addBidirectionalLink(network, SWITCH_ID_E, SWITCH_ID_F, 3, 2, 2);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 30 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method failToFindASwitchMaxWeightStrategy.

@Test(expected = UnroutableFlowException.class)
public void failToFindASwitchMaxWeightStrategy() throws UnroutableFlowException {
    AvailableNetwork network = buildTestNetwork();
    SwitchId srcDpid = new SwitchId("00:00:00:00:00:00:00:ff");
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    pathFinder.findPathWithWeightCloseToMaxWeight(network, srcDpid, SWITCH_ID_F, WEIGHT_FUNCTION, Long.MAX_VALUE, Long.MAX_VALUE);
}
Also used : 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