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