@Test public void testCompareFilters() { BDD dstIp0 = PKT.getDstIp().value(0); BDD dstIp1 = PKT.getDstIp().value(1); BDD srcIp0 = PKT.getSrcIp().value(0); BDD dstPort0 = PKT.getDstPort().value(0); BDD srcPort0 = PKT.getSrcPort().value(0); List<BDD> zeroBdds = aclBdds(dstIp0, srcIp0, dstPort0, srcPort0); List<BDD> emptyAclBdds = ImmutableList.of(PKT.getFactory().one()); List<LineAction> emptyAclActions = ImmutableList.of(); List<LineAction> pppp = ImmutableList.of(PERMIT, PERMIT, PERMIT, PERMIT); List<LineAction> dpdp = ImmutableList.of(DENY, PERMIT, DENY, PERMIT); assertThat(compare(pppp, zeroBdds, pppp, zeroBdds), empty()); assertThat( compare(emptyAclActions, emptyAclBdds, pppp, zeroBdds), contains( difference(null, 0), difference(null, 1), difference(null, 2), difference(null, 3))); assertThat( compare(emptyAclActions, emptyAclBdds, dpdp, zeroBdds), contains(difference(null, 1), difference(null, 3))); assertThat( compare(pppp, zeroBdds, emptyAclActions, emptyAclBdds), contains( difference(0, null), difference(1, null), difference(2, null), difference(3, null))); assertThat( compare(dpdp, zeroBdds, emptyAclActions, emptyAclBdds), contains(difference(1, null), difference(3, null))); { List<BDD> currentAcl = zeroBdds; List<BDD> referenceAcl = aclBdds(dstIp1, srcIp0, dstPort0, srcPort0); assertThat( compare(pppp, currentAcl, pppp, referenceAcl), contains(difference(0, null), difference(null, 0))); List<FilterDifference> compare = compare(dpdp, currentAcl, dpdp, referenceAcl); assertThat( compare, contains(difference(0, 1), difference(0, 3), difference(1, 0), difference(3, 0))); } }
@VisibleForTesting static Stream<FilterDifference> compareFilters( String hostname, String filtername, List<PermitAndDenyBdds> currentLineBdds, List<PermitAndDenyBdds> referenceLineBdds, BDDPacket bddPacket) { checkArgument(!currentLineBdds.isEmpty()); checkArgument(!referenceLineBdds.isEmpty()); assert bddPacket .getFactory() .orAll( currentLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); assert bddPacket .getFactory() .orAll( referenceLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); return IntStream.range(0, currentLineBdds.size()) .mapToObj( i -> { PermitAndDenyBdds currentLineBdd = currentLineBdds.get(i); return IntStream.range(0, referenceLineBdds.size()) .filter(j -> takeDifferentActions(currentLineBdd, referenceLineBdds.get(j))) .mapToObj( j -> new FilterDifference( hostname, filtername, i < currentLineBdds.size() - 1 ? i : null, j < referenceLineBdds.size() - 1 ? j : null)); }) .flatMap(Function.identity()); }
CompareFiltersAnswerer extends Answerer { @VisibleForTesting static Stream<FilterDifference> compareFilters( String hostname, String filtername, List<PermitAndDenyBdds> currentLineBdds, List<PermitAndDenyBdds> referenceLineBdds, BDDPacket bddPacket) { checkArgument(!currentLineBdds.isEmpty()); checkArgument(!referenceLineBdds.isEmpty()); assert bddPacket .getFactory() .orAll( currentLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); assert bddPacket .getFactory() .orAll( referenceLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); return IntStream.range(0, currentLineBdds.size()) .mapToObj( i -> { PermitAndDenyBdds currentLineBdd = currentLineBdds.get(i); return IntStream.range(0, referenceLineBdds.size()) .filter(j -> takeDifferentActions(currentLineBdd, referenceLineBdds.get(j))) .mapToObj( j -> new FilterDifference( hostname, filtername, i < currentLineBdds.size() - 1 ? i : null, j < referenceLineBdds.size() - 1 ? j : null)); }) .flatMap(Function.identity()); } }
CompareFiltersAnswerer extends Answerer { @VisibleForTesting static Stream<FilterDifference> compareFilters( String hostname, String filtername, List<PermitAndDenyBdds> currentLineBdds, List<PermitAndDenyBdds> referenceLineBdds, BDDPacket bddPacket) { checkArgument(!currentLineBdds.isEmpty()); checkArgument(!referenceLineBdds.isEmpty()); assert bddPacket .getFactory() .orAll( currentLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); assert bddPacket .getFactory() .orAll( referenceLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); return IntStream.range(0, currentLineBdds.size()) .mapToObj( i -> { PermitAndDenyBdds currentLineBdd = currentLineBdds.get(i); return IntStream.range(0, referenceLineBdds.size()) .filter(j -> takeDifferentActions(currentLineBdd, referenceLineBdds.get(j))) .mapToObj( j -> new FilterDifference( hostname, filtername, i < currentLineBdds.size() - 1 ? i : null, j < referenceLineBdds.size() - 1 ? j : null)); }) .flatMap(Function.identity()); } CompareFiltersAnswerer(CompareFiltersQuestion question, IBatfish batfish); }
CompareFiltersAnswerer extends Answerer { @VisibleForTesting static Stream<FilterDifference> compareFilters( String hostname, String filtername, List<PermitAndDenyBdds> currentLineBdds, List<PermitAndDenyBdds> referenceLineBdds, BDDPacket bddPacket) { checkArgument(!currentLineBdds.isEmpty()); checkArgument(!referenceLineBdds.isEmpty()); assert bddPacket .getFactory() .orAll( currentLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); assert bddPacket .getFactory() .orAll( referenceLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); return IntStream.range(0, currentLineBdds.size()) .mapToObj( i -> { PermitAndDenyBdds currentLineBdd = currentLineBdds.get(i); return IntStream.range(0, referenceLineBdds.size()) .filter(j -> takeDifferentActions(currentLineBdd, referenceLineBdds.get(j))) .mapToObj( j -> new FilterDifference( hostname, filtername, i < currentLineBdds.size() - 1 ? i : null, j < referenceLineBdds.size() - 1 ? j : null)); }) .flatMap(Function.identity()); } CompareFiltersAnswerer(CompareFiltersQuestion question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); @Override AnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference); }
CompareFiltersAnswerer extends Answerer { @VisibleForTesting static Stream<FilterDifference> compareFilters( String hostname, String filtername, List<PermitAndDenyBdds> currentLineBdds, List<PermitAndDenyBdds> referenceLineBdds, BDDPacket bddPacket) { checkArgument(!currentLineBdds.isEmpty()); checkArgument(!referenceLineBdds.isEmpty()); assert bddPacket .getFactory() .orAll( currentLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); assert bddPacket .getFactory() .orAll( referenceLineBdds.stream() .flatMap(bdds -> Stream.of(bdds.getPermitBdd(), bdds.getDenyBdd())) .collect(ImmutableList.toImmutableList())) .isOne(); return IntStream.range(0, currentLineBdds.size()) .mapToObj( i -> { PermitAndDenyBdds currentLineBdd = currentLineBdds.get(i); return IntStream.range(0, referenceLineBdds.size()) .filter(j -> takeDifferentActions(currentLineBdd, referenceLineBdds.get(j))) .mapToObj( j -> new FilterDifference( hostname, filtername, i < currentLineBdds.size() - 1 ? i : null, j < referenceLineBdds.size() - 1 ? j : null)); }) .flatMap(Function.identity()); } CompareFiltersAnswerer(CompareFiltersQuestion question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); @Override AnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference);  }