@Test public void shouldValidateOneSwitchFlow() throws FlowNotFoundException, SwitchNotFoundException { buildOneSwitchPortFlow(); List<SwitchFlowEntries> switchEntries = getSwitchFlowEntriesOneSwitchFlow(); List<SwitchMeterEntries> meterEntries = getSwitchMeterEntriesOneSwitchFlow(); List<FlowValidationResponse> result = service.validateFlow(TEST_FLOW_ID_B, switchEntries, meterEntries); assertEquals(2, result.size()); assertEquals(0, result.get(0).getDiscrepancies().size()); assertEquals(0, result.get(1).getDiscrepancies().size()); }
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig,
                                 long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig,
                                 long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries,
                                                     List<SwitchMeterEntries> switchMeterEntries); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig,
                                 long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries,
                                                     List<SwitchMeterEntries> switchMeterEntries);  }