use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkUsingCostStrategy.
@Test
public void shouldBuildAvailableNetworkUsingCostStrategy() throws RecoverableException {
Flow flow = getFlow(false);
IslImmutableView isl = getIslView(flow);
when(config.getNetworkStrategy()).thenReturn("COST");
when(islRepository.findActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class BestWeightAndShortestPathFinderTest method shouldChooseCheaperOverTooDeepForReverseOrderMaxWeightStrategy.
@Test
public void shouldChooseCheaperOverTooDeepForReverseOrderMaxWeightStrategy() throws UnroutableFlowException {
AvailableNetwork network = buildLongAndExpensivePathsNetwork();
BestWeightAndShortestPathFinder pathFinder = new BestWeightAndShortestPathFinder(2);
Pair<List<Edge>, List<Edge>> pairPath = pathFinder.findPathWithWeightCloseToMaxWeight(network, SWITCH_ID_3, SWITCH_ID_1, WEIGHT_FUNCTION, Long.MAX_VALUE, Long.MAX_VALUE).getFoundPath();
List<Edge> fpath = pairPath.getLeft();
assertThat(fpath, Matchers.hasSize(2));
assertEquals(SWITCH_ID_2, fpath.get(1).getSrcSwitch().getSwitchId());
List<Edge> rpath = pairPath.getRight();
assertThat(rpath, Matchers.hasSize(2));
assertEquals(SWITCH_ID_2, rpath.get(0).getDestSwitch().getSwitchId());
}
use of org.openkilda.pce.impl.AvailableNetwork in project open-kilda by telstra.
the class AvailableNetworkFactory method getAvailableNetwork.
/**
* Gets a {@link AvailableNetwork}.
*
* @param flow the flow, for which {@link AvailableNetwork} is constructing.
* @param reusePathsResources reuse resources already allocated by {@param reusePathsResources} paths.
* @return {@link AvailableNetwork} instance.
*/
public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException {
BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy());
AvailableNetwork network = new AvailableNetwork();
try {
// Reads all active links from the database and creates representation of the network.
getAvailableIsls(buildStrategy, flow).forEach(link -> addIslAsEdge(link, network));
if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) {
reusePathsResources.stream().filter(pathId -> flowPathRepository.findById(pathId).map(path -> !path.isIgnoreBandwidth()).orElse(false)).forEach(pathId -> {
// ISLs occupied by the flow (take the bandwidth already occupied by the flow into account).
islRepository.findActiveByPathAndBandwidthAndEncapsulationType(pathId, flow.getBandwidth(), flow.getEncapsulationType()).forEach(link -> addIslAsEdge(link, network));
});
}
} catch (PersistenceException e) {
throw new RecoverableException("An error from the database", e);
}
if (flow.getDiverseGroupId() != null) {
log.info("Filling AvailableNetwork diverse weights for group with id {}", flow.getDiverseGroupId());
Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowDiverseGroupId(flow.getDiverseGroupId());
if (!reusePathsResources.isEmpty()) {
flowPaths = flowPaths.stream().filter(s -> !reusePathsResources.contains(s)).collect(Collectors.toList());
}
Collection<PathId> affinityPathIds = flowPathRepository.findPathIdsByFlowAffinityGroupId(flow.getAffinityGroupId());
flowPaths.forEach(pathId -> flowPathRepository.findById(pathId).filter(flowPath -> !affinityPathIds.contains(flowPath.getPathId()) || flowPath.getFlowId().equals(flow.getFlowId())).ifPresent(flowPath -> {
network.processDiversitySegments(flowPath.getSegments(), flow);
network.processDiversitySegmentsWithPop(flowPath.getSegments());
}));
}
// The main flow should not take into account the rest of the flows in this affinity group.
if (flow.getAffinityGroupId() != null && !flow.getAffinityGroupId().equals(flow.getFlowId())) {
log.info("Filling AvailableNetwork affinity weights for group with id {}", flow.getAffinityGroupId());
flowPathRepository.findByFlowId(flow.getAffinityGroupId()).stream().filter(flowPath -> !flowPath.isProtected()).filter(FlowPath::isForward).map(FlowPath::getSegments).forEach(network::processAffinitySegments);
}
return network;
}
Aggregations