use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method buildExpensiveNetwork.
private AvailableNetwork buildExpensiveNetwork() {
/*
* Triangle topology:
*
* SW1---2 000 000 000---SW2---2 000 000 000---SW3
* | |
* +---------------------1---------------------+
*/
AvailableNetwork network = new AvailableNetwork();
// cost near to MAX_INTEGER
addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_2, 1, 2, 2000000000);
// cost near to MAX_INTEGER
addBidirectionalLink(network, SWITCH_ID_2, SWITCH_ID_3, 3, 4, 2000000000);
addBidirectionalLink(network, SWITCH_ID_1, SWITCH_ID_3, 5, 6, 1);
return network;
}
use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method findThePathBottomClosestToMaxWeight.
private FindPathResult findThePathBottomClosestToMaxWeight(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 200
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
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;
}
use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method shouldChooseExpensiveWithSameDepthMaxWeightStrategy.
@Test
public void shouldChooseExpensiveWithSameDepthMaxWeightStrategy() throws UnroutableFlowException {
AvailableNetwork network = buildLongAndExpensivePathsNetwork();
BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(3);
Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_1, SWITCH_ID_5, WEIGHT_FUNCTION, Long.MAX_VALUE, Long.MAX_VALUE).getFoundPath();
List<Edge> fpath = pairPath.getLeft();
assertThat(fpath, Matchers.hasSize(3));
assertEquals(SWITCH_ID_4, fpath.get(2).getSrcSwitch().getSwitchId());
List<Edge> rpath = pairPath.getRight();
assertThat(rpath, Matchers.hasSize(3));
assertEquals(SWITCH_ID_4, rpath.get(0).getDestSwitch().getSwitchId());
}
use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method shouldFailWhenPathIsLongerThenAllowedDepthMaxWeightStrategy.
@Test(expected = UnroutableFlowException.class)
public void shouldFailWhenPathIsLongerThenAllowedDepthMaxWeightStrategy() throws UnroutableFlowException {
AvailableNetwork network = buildTestNetwork();
BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(1);
pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_D, SWITCH_ID_F, WEIGHT_FUNCTION, Long.MAX_VALUE, Long.MAX_VALUE);
}
use of org.openkilda.pce.impl.AvailableNetwork 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;
}
Aggregations