Search in sources :

Example 21 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldAddIntermediateSwitchWeightOnce.

@Test
public void shouldAddIntermediateSwitchWeightOnce() throws UnroutableFlowException {
    AvailableNetwork network = buildTestNetwork();
    // shouldn't affect path if added once
    network.getSwitch(SWITCH_ID_A).increaseDiversityGroupUseCounter();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    Pair<List<Edge>, List<Edge>> paths = pathFinder.findPathWithMinWeight(network, SWITCH_ID_D, SWITCH_ID_F, WEIGHT_FUNCTION).getFoundPath();
    assertEquals(Arrays.asList(SWITCH_ID_D, SWITCH_ID_A, SWITCH_ID_F), getSwitchIdsFlowPath(paths.getLeft()));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork) Test(org.junit.Test)

Example 22 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method buildThreePathsNetwork.

private AvailableNetwork buildThreePathsNetwork() {
    /*
            2
          /   \
         1--3--5
          \   /
            4
         */
    // Path 1>2>5 = 198cost
    // Path 1>3>5 = 200cost
    // Path 1>4>5 = 201cost
    AvailableNetwork network = new AvailableNetwork();
    // 1>2>5
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 1, 100);
    addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_5, 2, 1, 98);
    // 1>3>5
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_3, 2, 1, 100);
    addBidirectionalLink(network, SWITCH_ID_3, SWITCH_ID_5, 2, 2, 100);
    // 1>4>5
    addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_4, 3, 1, 100);
    addBidirectionalLink(network, SWITCH_ID_4, SWITCH_ID_5, 2, 3, 101);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 23 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldHandleVeryExpensiveLinks.

@Test
public void shouldHandleVeryExpensiveLinks() throws UnroutableFlowException {
    AvailableNetwork network = buildExpensiveNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    Pair<List<Edge>, List<Edge>> paths = pathFinder.findPathWithMinWeight(network, SWITCH_ID_1, SWITCH_ID_3, WEIGHT_FUNCTION).getFoundPath();
    List<SwitchId> forwardSwitchPath = getSwitchIdsFlowPath(paths.getLeft());
    List<SwitchId> reverseSwitchPath = Lists.reverse(getSwitchIdsFlowPath(paths.getRight()));
    assertEquals(forwardSwitchPath, reverseSwitchPath);
    assertEquals(forwardSwitchPath, Lists.newArrayList(SWITCH_ID_1, SWITCH_ID_3));
}
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)

Example 24 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method buildTestNetworkForVerifyIslConfig.

private AvailableNetwork buildTestNetworkForVerifyIslConfig(boolean shortestPathHasUnderMaintenanceLink, boolean shortPathHasUnstableLink) {
    /*
         *   Topology:
         *
         *   A-------B
         *   |\     /|
         *   | +-C-+ |
         *   D-------E
         */
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SWITCH_ID_A, SWITCH_ID_B, 1, 1, 0, 0, false, shortestPathHasUnderMaintenanceLink);
    addLink(network, SWITCH_ID_A, SWITCH_ID_C, 2, 1, 0, 0, false, false);
    addLink(network, SWITCH_ID_C, SWITCH_ID_B, 2, 2, 0, 0, shortPathHasUnstableLink, false);
    addLink(network, SWITCH_ID_A, SWITCH_ID_D, 3, 1, 0, 0, false, false);
    addLink(network, SWITCH_ID_D, SWITCH_ID_E, 1, 1, 0, 0, false, false);
    addLink(network, SWITCH_ID_E, SWITCH_ID_B, 2, 3, 0, 0, false, false);
    return network;
}
Also used : AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 25 with AvailableNetwork

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

the class BestWeightAndShortestPathFinderTest method shouldChooseExpensiveOverTooDeep.

@Test
public void shouldChooseExpensiveOverTooDeep() throws UnroutableFlowException {
    AvailableNetwork network = buildLongAndExpensivePathsNetwork();
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(2);
    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(2));
    assertEquals(SWITCH_ID_2, fpath.get(1).getSrcSwitch().getSwitchId());
    List<Edge> rpath = pairPath.getRight();
    assertThat(rpath, Matchers.hasSize(2));
    assertEquals(SWITCH_ID_2, 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)

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