@Test public void validateDefaultRules() throws SwitchNotFoundException { ValidationService validationService = new ValidationServiceImpl(persistenceManager().build(), topologyConfig); List<FlowEntry> flowEntries = Lists.newArrayList(FlowEntry.builder().cookie(0x8000000000000001L).priority(1).byteCount(123).build(), FlowEntry.builder().cookie(0x8000000000000001L).priority(2).build(), FlowEntry.builder().cookie(0x8000000000000002L).priority(1).build(), FlowEntry.builder().cookie(0x8000000000000002L).priority(2).build(), FlowEntry.builder().cookie(0x8000000000000004L).priority(1).build()); List<FlowEntry> expectedDefaultFlowEntries = Lists.newArrayList(FlowEntry.builder().cookie(0x8000000000000001L).priority(1).byteCount(321).build(), FlowEntry.builder().cookie(0x8000000000000002L).priority(3).build(), FlowEntry.builder().cookie(0x8000000000000003L).priority(1).build()); ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, flowEntries, expectedDefaultFlowEntries); assertEquals(ImmutableSet.of(0x8000000000000001L), new HashSet<>(response.getProperRules())); assertEquals(ImmutableSet.of(0x8000000000000001L, 0x8000000000000002L), new HashSet<>(response.getMisconfiguredRules())); assertEquals(ImmutableSet.of(0x8000000000000003L), new HashSet<>(response.getMissingRules())); assertEquals(ImmutableSet.of(0x8000000000000004L), new HashSet<>(response.getExcessRules())); }
private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules,
                                             List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters,
                                               List<MeterEntry> expectedDefaultMeters); }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules,
                                             List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters,
                                               List<MeterEntry> expectedDefaultMeters);  }