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));
}
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;
}
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;
}
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));
}
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;
}
Aggregations