use of org.openkilda.pce.model.WeightFunction in project open-kilda by telstra.
the class AvailableNetworkTest method shouldUpdateEdgeWeightWithPopDiversityPenalty.
@Test
public void shouldUpdateEdgeWeightWithPopDiversityPenalty() {
int cost = 700;
final WeightFunction weightFunction = WEIGHT_FUNCTION;
AvailableNetwork network = new AvailableNetwork();
addLink(network, SWITCH_1, SWITCH_2, 1, 2, cost, 5, POP_1, POP_2);
addLink(network, SWITCH_1, SWITCH_3, 2, 1, cost, 5, POP_1, POP_4);
addLink(network, SWITCH_1, SWITCH_4, 3, 1, cost, 5, POP_1, POP_4);
addLink(network, SWITCH_5, SWITCH_4, 1, 2, cost, 5, POP_3, POP_4);
addLink(network, SWITCH_5, SWITCH_3, 2, 2, cost, 5, POP_3, POP_4);
addLink(network, SWITCH_5, SWITCH_2, 3, 2, cost, 5, POP_3, POP_2);
network.processDiversitySegmentsWithPop(asList(buildPathWithSegment(SWITCH_1, SWITCH_3, 2, 1, POP_1, POP_4, 0), buildPathWithSegment(SWITCH_3, SWITCH_5, 2, 2, POP_4, POP_3, 1)));
long expectedWeight = cost + 1000L;
for (Edge edge : network.edges) {
long currentWeight = weightFunction.apply(edge).toLong();
if (edge.getSrcSwitch().getPop().equals(POP_4) || edge.getDestSwitch().getPop().equals(POP_4)) {
assertEquals(expectedWeight, currentWeight);
} else {
assertEquals(cost, currentWeight);
}
}
}
use of org.openkilda.pce.model.WeightFunction in project open-kilda by telstra.
the class AvailableNetworkTest method shouldNotUpdateWeightsWhenTransitSegmentsOnlyInPop.
@Test
public void shouldNotUpdateWeightsWhenTransitSegmentsOnlyInPop() {
int cost = 700;
final WeightFunction weightFunction = WEIGHT_FUNCTION;
AvailableNetwork network = new AvailableNetwork();
addLink(network, SWITCH_1, SWITCH_2, 1, 2, cost, 5, null, null);
addLink(network, SWITCH_1, SWITCH_3, 2, 1, cost, 5, null, POP_4);
addLink(network, SWITCH_1, SWITCH_4, 3, 1, cost, 5, null, null);
addLink(network, SWITCH_5, SWITCH_4, 1, 2, cost, 5, null, null);
addLink(network, SWITCH_5, SWITCH_3, 2, 2, cost, 5, null, POP_4);
addLink(network, SWITCH_5, SWITCH_2, 3, 2, cost, 5, null, null);
network.processDiversitySegmentsWithPop(asList(buildPathWithSegment(SWITCH_1, SWITCH_3, 2, 1, POP_1, null, 0), buildPathWithSegment(SWITCH_3, SWITCH_5, 2, 2, null, POP_3, 1)));
for (Edge edge : network.edges) {
long currentWeight = weightFunction.apply(edge).toLong();
assertEquals(cost, currentWeight);
}
}
use of org.openkilda.pce.model.WeightFunction in project open-kilda by telstra.
the class AvailableNetworkTest method shouldNotUpdateEdgeWeightWithPopDiversityPenaltyIfNoPop.
@Test
public void shouldNotUpdateEdgeWeightWithPopDiversityPenaltyIfNoPop() {
int cost = 700;
final WeightFunction weightFunction = WEIGHT_FUNCTION;
AvailableNetwork network = new AvailableNetwork();
addLink(network, SWITCH_1, SWITCH_2, 1, 2, cost, 5);
addLink(network, SWITCH_1, SWITCH_3, 2, 1, cost, 5);
addLink(network, SWITCH_1, SWITCH_4, 3, 1, cost, 5);
addLink(network, SWITCH_5, SWITCH_4, 1, 2, cost, 5);
addLink(network, SWITCH_5, SWITCH_3, 2, 2, cost, 5);
addLink(network, SWITCH_5, SWITCH_2, 3, 2, cost, 5);
network.processDiversitySegmentsWithPop(asList(buildPathSegment(SWITCH_1, SWITCH_3, 2, 1, 0), buildPathSegment(SWITCH_3, SWITCH_5, 2, 2, 1)));
for (Edge edge : network.edges) {
long currentWeight = weightFunction.apply(edge).toLong();
assertEquals(cost, currentWeight);
}
}
use of org.openkilda.pce.model.WeightFunction in project open-kilda by telstra.
the class AvailableNetworkTest method shouldNotUpdateWeightsWhenTransitSegmentsNotInPop.
@Test
public void shouldNotUpdateWeightsWhenTransitSegmentsNotInPop() {
int cost = 700;
final WeightFunction weightFunction = WEIGHT_FUNCTION;
AvailableNetwork network = new AvailableNetwork();
addLink(network, SWITCH_1, SWITCH_2, 1, 2, cost, 5, POP_1, POP_2);
addLink(network, SWITCH_1, SWITCH_3, 2, 1, cost, 5, POP_1, null);
addLink(network, SWITCH_1, SWITCH_4, 3, 1, cost, 5, POP_1, POP_4);
addLink(network, SWITCH_5, SWITCH_4, 1, 2, cost, 5, POP_3, POP_4);
addLink(network, SWITCH_5, SWITCH_3, 2, 2, cost, 5, POP_3, null);
addLink(network, SWITCH_5, SWITCH_2, 3, 2, cost, 5, POP_3, POP_2);
network.processDiversitySegmentsWithPop(asList(buildPathWithSegment(SWITCH_1, SWITCH_3, 2, 1, POP_1, null, 0), buildPathWithSegment(SWITCH_3, SWITCH_5, 2, 2, null, POP_3, 1)));
for (Edge edge : network.edges) {
long currentWeight = weightFunction.apply(edge).toLong();
assertEquals(cost, currentWeight);
}
}
use of org.openkilda.pce.model.WeightFunction in project open-kilda by telstra.
the class InMemoryPathComputer method getPath.
private GetPathsResult getPath(AvailableNetwork network, Flow flow, PathComputationStrategy strategy) throws UnroutableFlowException {
if (flow.isOneSwitchFlow()) {
log.info("No path computation for one-switch flow");
SwitchId singleSwitchId = flow.getSrcSwitchId();
return GetPathsResult.builder().forward(convertToPath(singleSwitchId, singleSwitchId, emptyList())).reverse(convertToPath(singleSwitchId, singleSwitchId, emptyList())).backUpPathComputationWayUsed(false).build();
}
WeightFunction weightFunction = getWeightFunctionByStrategy(strategy);
FindPathResult findPathResult;
try {
findPathResult = findPathInNetwork(flow, network, weightFunction, strategy);
} catch (UnroutableFlowException e) {
String message = format("Failed to find path with requested bandwidth=%s: %s", flow.isIgnoreBandwidth() ? " ignored" : flow.getBandwidth(), e.getMessage());
throw new UnroutableFlowException(message, e, flow.getFlowId(), flow.isIgnoreBandwidth());
}
return convertToGetPathsResult(flow.getSrcSwitchId(), flow.getDestSwitchId(), findPathResult, strategy, flow.getPathComputationStrategy());
}
Aggregations