@Test public void shouldIncreaseDiversityGroupUseCounter() throws RecoverableException { List<Isl> isls = new ArrayList<>(); isls.addAll(getBidirectionalIsls(switchA, 1, switchB, 2)); isls.addAll(getBidirectionalIsls(switchB, 3, switchC, 4)); final Flow diverseFlow = Flow.builder() .flowId(FLOW_ID_1) .groupId(GROUP_ID) .srcSwitch(switchB) .destSwitch(switchD) .build(); FlowPath forwardPath = FlowPath.builder() .srcSwitch(switchB) .destSwitch(switchD) .pathId(FORWARD_PATH_ID) .segments(Collections.singletonList(PathSegment.builder() .srcSwitch(switchB).srcPort(SRC_PORT).destSwitch(switchD).destPort(DEST_PORT).build())) .build(); when(flowPathRepository.findById(FORWARD_PATH_ID)).thenReturn(java.util.Optional.of(forwardPath)); FlowPath reversePath = FlowPath.builder() .srcSwitch(switchD) .destSwitch(switchB) .pathId(REVERSE_PATH_ID) .segments(Collections.singletonList(PathSegment.builder() .srcSwitch(switchD).srcPort(DEST_PORT).destSwitch(switchB).destPort(SRC_PORT).build())) .build(); when(flowPathRepository.findById(REVERSE_PATH_ID)).thenReturn(java.util.Optional.of(reversePath)); Flow flow = getFlow(false); flow.setSrcSwitch(switchA); flow.setDestSwitch(switchC); flow.setGroupId(GROUP_ID); when(config.getNetworkStrategy()).thenReturn(BuildStrategy.COST.name()); when(islRepository.findActiveWithAvailableBandwidth(flow.getBandwidth(), flow.getEncapsulationType())) .thenReturn(isls); when(flowPathRepository.findPathIdsByFlowGroupId(GROUP_ID)) .thenReturn(Lists.newArrayList(FORWARD_PATH_ID, REVERSE_PATH_ID)); AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList()); assertEquals(2, availableNetwork.getSwitch(switchB.getSwitchId()).getDiversityGroupUseCounter()); }
public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException { BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy()); AvailableNetwork network = new AvailableNetwork(); try { Collection<Isl> links = getAvailableIsls(buildStrategy, flow); links.forEach(network::addLink); if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) { reusePathsResources.forEach(pathId -> { Collection<Isl> flowLinks = islRepository.findActiveAndOccupiedByFlowPathWithAvailableBandwidth( pathId, flow.getBandwidth(), flow.getEncapsulationType()); flowLinks.forEach(network::addLink); }); } } catch (PersistenceException e) { throw new RecoverableException("An error from the database", e); } if (flow.getGroupId() != null) { log.info("Filling AvailableNetwork diverse weighs for group with id {}", flow.getGroupId()); Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowGroupId(flow.getGroupId()); if (!reusePathsResources.isEmpty()) { flowPaths = flowPaths.stream() .filter(s -> !reusePathsResources.contains(s)) .collect(Collectors.toList()); } flowPaths.forEach(pathId -> flowPathRepository.findById(pathId) .ifPresent(flowPath -> { network.processDiversitySegments(flowPath.getSegments()); network.processDiversitySegmentsWithPop(flowPath.getSegments()); })); } return network; }
AvailableNetworkFactory { public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException { BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy()); AvailableNetwork network = new AvailableNetwork(); try { Collection<Isl> links = getAvailableIsls(buildStrategy, flow); links.forEach(network::addLink); if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) { reusePathsResources.forEach(pathId -> { Collection<Isl> flowLinks = islRepository.findActiveAndOccupiedByFlowPathWithAvailableBandwidth( pathId, flow.getBandwidth(), flow.getEncapsulationType()); flowLinks.forEach(network::addLink); }); } } catch (PersistenceException e) { throw new RecoverableException("An error from the database", e); } if (flow.getGroupId() != null) { log.info("Filling AvailableNetwork diverse weighs for group with id {}", flow.getGroupId()); Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowGroupId(flow.getGroupId()); if (!reusePathsResources.isEmpty()) { flowPaths = flowPaths.stream() .filter(s -> !reusePathsResources.contains(s)) .collect(Collectors.toList()); } flowPaths.forEach(pathId -> flowPathRepository.findById(pathId) .ifPresent(flowPath -> { network.processDiversitySegments(flowPath.getSegments()); network.processDiversitySegmentsWithPop(flowPath.getSegments()); })); } return network; } }
AvailableNetworkFactory { public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException { BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy()); AvailableNetwork network = new AvailableNetwork(); try { Collection<Isl> links = getAvailableIsls(buildStrategy, flow); links.forEach(network::addLink); if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) { reusePathsResources.forEach(pathId -> { Collection<Isl> flowLinks = islRepository.findActiveAndOccupiedByFlowPathWithAvailableBandwidth( pathId, flow.getBandwidth(), flow.getEncapsulationType()); flowLinks.forEach(network::addLink); }); } } catch (PersistenceException e) { throw new RecoverableException("An error from the database", e); } if (flow.getGroupId() != null) { log.info("Filling AvailableNetwork diverse weighs for group with id {}", flow.getGroupId()); Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowGroupId(flow.getGroupId()); if (!reusePathsResources.isEmpty()) { flowPaths = flowPaths.stream() .filter(s -> !reusePathsResources.contains(s)) .collect(Collectors.toList()); } flowPaths.forEach(pathId -> flowPathRepository.findById(pathId) .ifPresent(flowPath -> { network.processDiversitySegments(flowPath.getSegments()); network.processDiversitySegmentsWithPop(flowPath.getSegments()); })); } return network; } AvailableNetworkFactory(PathComputerConfig config, RepositoryFactory repositoryFactory); }
AvailableNetworkFactory { public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException { BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy()); AvailableNetwork network = new AvailableNetwork(); try { Collection<Isl> links = getAvailableIsls(buildStrategy, flow); links.forEach(network::addLink); if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) { reusePathsResources.forEach(pathId -> { Collection<Isl> flowLinks = islRepository.findActiveAndOccupiedByFlowPathWithAvailableBandwidth( pathId, flow.getBandwidth(), flow.getEncapsulationType()); flowLinks.forEach(network::addLink); }); } } catch (PersistenceException e) { throw new RecoverableException("An error from the database", e); } if (flow.getGroupId() != null) { log.info("Filling AvailableNetwork diverse weighs for group with id {}", flow.getGroupId()); Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowGroupId(flow.getGroupId()); if (!reusePathsResources.isEmpty()) { flowPaths = flowPaths.stream() .filter(s -> !reusePathsResources.contains(s)) .collect(Collectors.toList()); } flowPaths.forEach(pathId -> flowPathRepository.findById(pathId) .ifPresent(flowPath -> { network.processDiversitySegments(flowPath.getSegments()); network.processDiversitySegmentsWithPop(flowPath.getSegments()); })); } return network; } AvailableNetworkFactory(PathComputerConfig config, RepositoryFactory repositoryFactory); AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources); }
AvailableNetworkFactory { public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException { BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy()); AvailableNetwork network = new AvailableNetwork(); try { Collection<Isl> links = getAvailableIsls(buildStrategy, flow); links.forEach(network::addLink); if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) { reusePathsResources.forEach(pathId -> { Collection<Isl> flowLinks = islRepository.findActiveAndOccupiedByFlowPathWithAvailableBandwidth( pathId, flow.getBandwidth(), flow.getEncapsulationType()); flowLinks.forEach(network::addLink); }); } } catch (PersistenceException e) { throw new RecoverableException("An error from the database", e); } if (flow.getGroupId() != null) { log.info("Filling AvailableNetwork diverse weighs for group with id {}", flow.getGroupId()); Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowGroupId(flow.getGroupId()); if (!reusePathsResources.isEmpty()) { flowPaths = flowPaths.stream() .filter(s -> !reusePathsResources.contains(s)) .collect(Collectors.toList()); } flowPaths.forEach(pathId -> flowPathRepository.findById(pathId) .ifPresent(flowPath -> { network.processDiversitySegments(flowPath.getSegments()); network.processDiversitySegmentsWithPop(flowPath.getSegments()); })); } return network; } AvailableNetworkFactory(PathComputerConfig config, RepositoryFactory repositoryFactory); AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources);  }