Search in sources :

Example 16 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldFindNPath.

@Test
public void shouldFindNPath() throws UnroutableFlowException {
    AvailableNetwork network = buildTestNetworkForTestYensAlgorithm();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    List<List<SwitchId>> expectedPaths = new ArrayList<>();
    // Cost is 5
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_D, SWITCH_ID_C, SWITCH_ID_F));
    List<List<Edge>> paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 1, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 7
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_D, SWITCH_ID_C, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 2, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 7
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_D, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 3, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 8
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_D, SWITCH_ID_C, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 4, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 8
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_C, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 5, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 8
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_D, SWITCH_ID_B, SWITCH_ID_C, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 6, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 8
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_D, SWITCH_ID_E, SWITCH_ID_C, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 7, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 9
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_D, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 8, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 9
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_D, SWITCH_ID_C, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 9, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 10
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_D, SWITCH_ID_E, SWITCH_ID_C, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 10, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 11
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_C, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 11, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 11
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_D, SWITCH_ID_B, SWITCH_ID_C, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 12, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    // Cost is 14
    expectedPaths.add(Lists.newArrayList(SWITCH_ID_A, SWITCH_ID_B, SWITCH_ID_C, SWITCH_ID_D, SWITCH_ID_E, SWITCH_ID_F));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 13, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
    paths = pathFinder.findNPathsBetweenSwitches(network, SWITCH_ID_A, SWITCH_ID_F, 500, WEIGHT_FUNCTION);
    assertEquals(expectedPaths, convertPaths(paths));
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Test(org.junit.Test)

Example 17 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method buildLongAndExpensivePathsNetwork.

private AvailableNetwork buildLongAndExpensivePathsNetwork() {
    /*
         *   Topology:
         *
         *   SW1---SW2~~~SW4
         *          |     |
         *         SW3---SW5
         *
         *   SW2 - SW4 is expensive by cost.
         */
    AvailableNetwork network = new AvailableNetwork();
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 2, 100);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_4, 3, 4, 10000);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_3, 5, 6, 100);
    addBidirectionalLink(network, SWITCH_ID_3, SWITCH_ID_5, 7, 8, 100);
    addBidirectionalLink(network, SWITCH_ID_4, SWITCH_ID_5, 9, 10, 100);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 18 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method findThePathClosestToMaxWeight.

private FindPathResult findThePathClosestToMaxWeight(long maxWeight, long backUpMaxWeight) throws UnroutableFlowException {
    // given 3 paths that cost: 198, 200, 201
    AvailableNetwork network = buildThreePathsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    // when: request a path with maxWeight 201
    FindPathResult pathResult = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION, maxWeight, backUpMaxWeight);
    Pair<List<Edge>, List<Edge>> pairPath = pathResult.getFoundPath();
    // then: system picks 200 path
    List<SwitchId> forwardSwitches = getInvolvedSwitches(pairPath.getLeft());
    assertThat(forwardSwitches, equalTo(Arrays.asList(SWITCH_ID_1, SWITCH_ID_3, SWITCH_ID_5)));
    assertThat(getInvolvedSwitches(pairPath.getRight()), equalTo(Lists.reverse(forwardSwitches)));
    return pathResult;
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) ArrayList(java.util.ArrayList) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 19 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldFindSymmetricPath.

@Test
public void shouldFindSymmetricPath() throws UnroutableFlowException {
    AvailableNetwork network = buildLinearNetworkWithPairLinks();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(2);
    Pair<List<Edge>, List<Edge>> pathPair = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_3, WEIGHT_FUNCTION).getFoundPath();
    List<Edge> forward = pathPair.getLeft();
    List<Edge> reverse = Lists.reverse(pathPair.getRight());
    List<Boolean> validation = IntStream.range(0, forward.size()).mapToObj(i -> Objects.equals(forward.get(i).getSrcPort(), reverse.get(i).getDestPort())).collect(Collectors.toList());
    assertFalse(validation.contains(false));
}
Also used : IntStream(java.util.stream.IntStream) PathWeight(org.openkilda.pce.model.PathWeight) Arrays(java.util.Arrays) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) WeightFunction(org.openkilda.pce.model.WeightFunction) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) Objects(java.util.Objects) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Edge(org.openkilda.pce.model.Edge) List(java.util.List) Lists(com.google.common.collect.Lists) SwitchId(org.openkilda.model.SwitchId) Pair(org.apache.commons.lang3.tuple.Pair) FindPathResult(org.openkilda.pce.model.FindPathResult) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) 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 20 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method buildEqualCostsNetwork.

private AvailableNetwork buildEqualCostsNetwork() {
    /*
         *   Topology:
         *
         *   SW1---SW2---SW4
         *          |     |
         *         SW3---SW5
         *
         *   All ISLs have equal cost.
         */
    AvailableNetwork network = new AvailableNetwork();
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 2, 100);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_4, 3, 4, 100);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_3, 5, 6, 100);
    addBidirectionalLink(network, SWITCH_ID_3, SWITCH_ID_5, 7, 8, 100);
    addBidirectionalLink(network, SWITCH_ID_4, SWITCH_ID_5, 9, 10, 100);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

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