Search in sources :

Example 11 with FindPathResult

use of org.openkilda.pce.model.FindPathResult in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method maxWeightStratAccountsForBothLinkDirections.

private FindPathResult maxWeightStratAccountsForBothLinkDirections(long maxWeight, long backUpMaxWeight) throws UnroutableFlowException {
    // given 2 paths with costs: path1 forward 100, path1 reverse 102, path2 forward 101, path2 reverse 100
    AvailableNetwork network = new AvailableNetwork();
    addLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 1, 100, 0, false, false);
    addLink(network, SWITCH_ID_2, SWITCH_ID_1, 1, 1, 102, 0, false, false);
    addLink(network, SWITCH_ID_1, SWITCH_ID_2, 2, 2, 101, 0, false, false);
    addLink(network, SWITCH_ID_2, SWITCH_ID_1, 2, 2, 100, 0, false, false);
    BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(ALLOWED_DEPTH);
    // when: request a path with maxWeight 103
    FindPathResult pathResult = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_2, WEIGHT_FUNCTION, maxWeight, backUpMaxWeight);
    Pair<List<Edge>, List<Edge>> pairPath = pathResult.getFoundPath();
    // then: pick path1, because its reverse cost is 102 which is the closest to 103
    // system skips path2 even though its forward cost is 101, which is closer to 103 than 100 (path1 forward)
    assertThat(pairPath.getLeft().get(0).getSrcPort(), equalTo(1));
    assertThat(pairPath.getRight().get(0).getSrcPort(), equalTo(1));
    return pathResult;
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) ArrayList(java.util.ArrayList) List(java.util.List) AvailableNetwork(org.openkilda.pce.impl.AvailableNetwork)

Example 12 with FindPathResult

use of org.openkilda.pce.model.FindPathResult in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method shouldReturnThePathClosestToMaxWeight.

/**
 * System picks path closest to maxWeight. Omit too cheap path, omit equal to maxWeight path
 */
@Test
public void shouldReturnThePathClosestToMaxWeight() throws UnroutableFlowException {
    // a path with maxWeight 201
    FindPathResult pathResult = findThePathClosestToMaxWeight(201L, Long.MAX_VALUE);
    assertFalse(pathResult.isBackUpPathComputationWayUsed());
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) Test(org.junit.Test)

Example 13 with FindPathResult

use of org.openkilda.pce.model.FindPathResult in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method addIntermediateSwitchWeightOnceMaxWeightStrategy.

private FindPathResult addIntermediateSwitchWeightOnceMaxWeightStrategy(long maxWeight, long backUpMaxWeight) throws UnroutableFlowException {
    // given 3 paths that cost: 198, 200, 201
    AvailableNetwork network = buildThreePathsNetwork();
    // switch on '200' path has a diversity weight increase
    network.getSwitch(SWITCH_ID_3).increaseDiversityGroupUseCounter();
    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 198 path (since 200 path is no longer '200' due to diversity weight rise)
    List<SwitchId> forwardSwitches = getInvolvedSwitches(pairPath.getLeft());
    assertThat(forwardSwitches, equalTo(Arrays.asList(SWITCH_ID_1, SWITCH_ID_2, 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 14 with FindPathResult

use of org.openkilda.pce.model.FindPathResult in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method backUpMaxWeightAccountsForBothLinkDirections.

/**
 * Check that we take into account both forward-way and reverse-way links when calculating path using MAX_LATENCY
 * strategy when backUpMaxWeight satisfies the path.
 */
@Test
public void backUpMaxWeightAccountsForBothLinkDirections() throws UnroutableFlowException {
    // a path with backUpMaxWeight 103
    FindPathResult pathResult = maxWeightStratAccountsForBothLinkDirections(50L, 103L);
    assertTrue(pathResult.isBackUpPathComputationWayUsed());
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) Test(org.junit.Test)

Example 15 with FindPathResult

use of org.openkilda.pce.model.FindPathResult in project open-kilda by telstra.

the class BestWeightAndShortestPathFinderTest method shouldCreatePathThrowMoreExpensiveWayMaxLatencyStrategy.

@Test
public void shouldCreatePathThrowMoreExpensiveWayMaxLatencyStrategy() throws UnroutableFlowException {
    FindPathResult pathResult = findPathThrowMoreExpensiveWayMaxLatencyStrategy(10201L, Long.MAX_VALUE);
    assertFalse(pathResult.isBackUpPathComputationWayUsed());
}
Also used : FindPathResult(org.openkilda.pce.model.FindPathResult) Test(org.junit.Test)

Aggregations

FindPathResult (org.openkilda.pce.model.FindPathResult)16 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)5 List (java.util.List)5 AvailableNetwork (org.openkilda.pce.impl.AvailableNetwork)5 SwitchId (org.openkilda.model.SwitchId)4 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)1 Edge (org.openkilda.pce.model.Edge)1 WeightFunction (org.openkilda.pce.model.WeightFunction)1