@Test public void testResolveStartLocations() { String hostname = "hostname"; String i0Name = "i0"; String i1Name = "i1"; Configuration snapshotConfig = getResolveStartLocationsConfig(hostname, i0Name, i1Name); snapshotConfig.getAllInterfaces().get(i0Name).setActive(false); Configuration referenceConfig = getResolveStartLocationsConfig(hostname, i0Name, i1Name); SortedMap<String, Configuration> snapshotConfigs = ImmutableSortedMap.of(snapshotConfig.getHostname(), snapshotConfig); SortedMap<String, Configuration> referenceConfigs = ImmutableSortedMap.of(referenceConfig.getHostname(), referenceConfig); SpecifierContext snapshotSpecifierContext = getMockSpecifierContext(snapshotConfigs); SpecifierContext referenceSpecifierContext = getMockSpecifierContext(referenceConfigs); NetworkId network = new NetworkId("network"); NetworkSnapshot snapshot = new NetworkSnapshot(network, new SnapshotId("snapshot")); NetworkSnapshot reference = new NetworkSnapshot(network, new SnapshotId("reference")); IBatfish mockBatfish = new IBatfishTestAdapter() { @Override public SpecifierContext specifierContext(NetworkSnapshot networkSnapshot) { return networkSnapshot.equals(snapshot) ? snapshotSpecifierContext : referenceSpecifierContext; } }; DifferentialReachabilityParameters parameters = new DifferentialReachabilityAnswerer(new DifferentialReachabilityQuestion(), mockBatfish) .parameters(snapshot, reference); Set<Location> startLocations = parameters.getIpSpaceAssignment().getEntries().stream() .map(IpSpaceAssignment.Entry::getLocations) .flatMap(Collection::stream) .collect(ImmutableSet.toImmutableSet()); Set<Location> expected = ImmutableSet.of( new InterfaceLocation(hostname, i1Name), new InterfaceLinkLocation(hostname, i1Name)); assertEquals(expected, startLocations); }
@VisibleForTesting DifferentialReachabilityParameters parameters( NetworkSnapshot snapshot, NetworkSnapshot reference) { DifferentialReachabilityQuestion question = (DifferentialReachabilityQuestion) _question; PacketHeaderConstraints headerConstraints = question.getHeaderConstraints(); SpecifierContext snapshotCtxt = _batfish.specifierContext(snapshot); SpecifierContext referenceCtxt = _batfish.specifierContext(reference); PathConstraints pathConstraints = createPathConstraints(question.getPathConstraints()); Set<String> forbiddenTransitNodes = Sets.union( pathConstraints.getForbiddenLocations().resolve(snapshotCtxt), pathConstraints.getForbiddenLocations().resolve(referenceCtxt)); Set<String> requiredTransitNodes = Sets.union( pathConstraints.getTransitLocations().resolve(snapshotCtxt), pathConstraints.getTransitLocations().resolve(referenceCtxt)); Set<Location> startLocations = Sets.intersection( resolveActiveLocations(pathConstraints.getStartLocation(), snapshotCtxt), resolveActiveLocations(pathConstraints.getStartLocation(), referenceCtxt)); if (startLocations.isEmpty()) { throw new BatfishException( "no matching startLocation is present and active in both snapshots"); } Set<String> finalNodes = Sets.union( pathConstraints.getEndLocation().resolve(snapshotCtxt), pathConstraints.getEndLocation().resolve(referenceCtxt)); IpSpaceAssignment ipSpaceAssignment = SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getSrcIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(startLocations, snapshotCtxt); IpSpace dstIps = firstNonNull( AclIpSpace.union( SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getDstIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(ImmutableSet.of(), snapshotCtxt).getEntries().stream() .map(Entry::getIpSpace) .collect(ImmutableList.toImmutableList())), UniverseIpSpace.INSTANCE); AclLineMatchExpr headerSpace = PacketHeaderConstraintsUtil.toAclLineMatchExpr( headerConstraints, UniverseIpSpace.INSTANCE, dstIps); return new DifferentialReachabilityParameters( ReachabilityParameters.filterDispositions(question.getActions().getDispositions()), forbiddenTransitNodes, finalNodes, headerSpace, question.getIgnoreFilters(), question.getInvertSearch(), ipSpaceAssignment, question.getMaxTraces(), requiredTransitNodes); }
DifferentialReachabilityAnswerer extends Answerer { @VisibleForTesting DifferentialReachabilityParameters parameters( NetworkSnapshot snapshot, NetworkSnapshot reference) { DifferentialReachabilityQuestion question = (DifferentialReachabilityQuestion) _question; PacketHeaderConstraints headerConstraints = question.getHeaderConstraints(); SpecifierContext snapshotCtxt = _batfish.specifierContext(snapshot); SpecifierContext referenceCtxt = _batfish.specifierContext(reference); PathConstraints pathConstraints = createPathConstraints(question.getPathConstraints()); Set<String> forbiddenTransitNodes = Sets.union( pathConstraints.getForbiddenLocations().resolve(snapshotCtxt), pathConstraints.getForbiddenLocations().resolve(referenceCtxt)); Set<String> requiredTransitNodes = Sets.union( pathConstraints.getTransitLocations().resolve(snapshotCtxt), pathConstraints.getTransitLocations().resolve(referenceCtxt)); Set<Location> startLocations = Sets.intersection( resolveActiveLocations(pathConstraints.getStartLocation(), snapshotCtxt), resolveActiveLocations(pathConstraints.getStartLocation(), referenceCtxt)); if (startLocations.isEmpty()) { throw new BatfishException( "no matching startLocation is present and active in both snapshots"); } Set<String> finalNodes = Sets.union( pathConstraints.getEndLocation().resolve(snapshotCtxt), pathConstraints.getEndLocation().resolve(referenceCtxt)); IpSpaceAssignment ipSpaceAssignment = SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getSrcIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(startLocations, snapshotCtxt); IpSpace dstIps = firstNonNull( AclIpSpace.union( SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getDstIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(ImmutableSet.of(), snapshotCtxt).getEntries().stream() .map(Entry::getIpSpace) .collect(ImmutableList.toImmutableList())), UniverseIpSpace.INSTANCE); AclLineMatchExpr headerSpace = PacketHeaderConstraintsUtil.toAclLineMatchExpr( headerConstraints, UniverseIpSpace.INSTANCE, dstIps); return new DifferentialReachabilityParameters( ReachabilityParameters.filterDispositions(question.getActions().getDispositions()), forbiddenTransitNodes, finalNodes, headerSpace, question.getIgnoreFilters(), question.getInvertSearch(), ipSpaceAssignment, question.getMaxTraces(), requiredTransitNodes); } }
DifferentialReachabilityAnswerer extends Answerer { @VisibleForTesting DifferentialReachabilityParameters parameters( NetworkSnapshot snapshot, NetworkSnapshot reference) { DifferentialReachabilityQuestion question = (DifferentialReachabilityQuestion) _question; PacketHeaderConstraints headerConstraints = question.getHeaderConstraints(); SpecifierContext snapshotCtxt = _batfish.specifierContext(snapshot); SpecifierContext referenceCtxt = _batfish.specifierContext(reference); PathConstraints pathConstraints = createPathConstraints(question.getPathConstraints()); Set<String> forbiddenTransitNodes = Sets.union( pathConstraints.getForbiddenLocations().resolve(snapshotCtxt), pathConstraints.getForbiddenLocations().resolve(referenceCtxt)); Set<String> requiredTransitNodes = Sets.union( pathConstraints.getTransitLocations().resolve(snapshotCtxt), pathConstraints.getTransitLocations().resolve(referenceCtxt)); Set<Location> startLocations = Sets.intersection( resolveActiveLocations(pathConstraints.getStartLocation(), snapshotCtxt), resolveActiveLocations(pathConstraints.getStartLocation(), referenceCtxt)); if (startLocations.isEmpty()) { throw new BatfishException( "no matching startLocation is present and active in both snapshots"); } Set<String> finalNodes = Sets.union( pathConstraints.getEndLocation().resolve(snapshotCtxt), pathConstraints.getEndLocation().resolve(referenceCtxt)); IpSpaceAssignment ipSpaceAssignment = SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getSrcIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(startLocations, snapshotCtxt); IpSpace dstIps = firstNonNull( AclIpSpace.union( SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getDstIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(ImmutableSet.of(), snapshotCtxt).getEntries().stream() .map(Entry::getIpSpace) .collect(ImmutableList.toImmutableList())), UniverseIpSpace.INSTANCE); AclLineMatchExpr headerSpace = PacketHeaderConstraintsUtil.toAclLineMatchExpr( headerConstraints, UniverseIpSpace.INSTANCE, dstIps); return new DifferentialReachabilityParameters( ReachabilityParameters.filterDispositions(question.getActions().getDispositions()), forbiddenTransitNodes, finalNodes, headerSpace, question.getIgnoreFilters(), question.getInvertSearch(), ipSpaceAssignment, question.getMaxTraces(), requiredTransitNodes); } DifferentialReachabilityAnswerer(Question question, IBatfish batfish); }
DifferentialReachabilityAnswerer extends Answerer { @VisibleForTesting DifferentialReachabilityParameters parameters( NetworkSnapshot snapshot, NetworkSnapshot reference) { DifferentialReachabilityQuestion question = (DifferentialReachabilityQuestion) _question; PacketHeaderConstraints headerConstraints = question.getHeaderConstraints(); SpecifierContext snapshotCtxt = _batfish.specifierContext(snapshot); SpecifierContext referenceCtxt = _batfish.specifierContext(reference); PathConstraints pathConstraints = createPathConstraints(question.getPathConstraints()); Set<String> forbiddenTransitNodes = Sets.union( pathConstraints.getForbiddenLocations().resolve(snapshotCtxt), pathConstraints.getForbiddenLocations().resolve(referenceCtxt)); Set<String> requiredTransitNodes = Sets.union( pathConstraints.getTransitLocations().resolve(snapshotCtxt), pathConstraints.getTransitLocations().resolve(referenceCtxt)); Set<Location> startLocations = Sets.intersection( resolveActiveLocations(pathConstraints.getStartLocation(), snapshotCtxt), resolveActiveLocations(pathConstraints.getStartLocation(), referenceCtxt)); if (startLocations.isEmpty()) { throw new BatfishException( "no matching startLocation is present and active in both snapshots"); } Set<String> finalNodes = Sets.union( pathConstraints.getEndLocation().resolve(snapshotCtxt), pathConstraints.getEndLocation().resolve(referenceCtxt)); IpSpaceAssignment ipSpaceAssignment = SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getSrcIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(startLocations, snapshotCtxt); IpSpace dstIps = firstNonNull( AclIpSpace.union( SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getDstIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(ImmutableSet.of(), snapshotCtxt).getEntries().stream() .map(Entry::getIpSpace) .collect(ImmutableList.toImmutableList())), UniverseIpSpace.INSTANCE); AclLineMatchExpr headerSpace = PacketHeaderConstraintsUtil.toAclLineMatchExpr( headerConstraints, UniverseIpSpace.INSTANCE, dstIps); return new DifferentialReachabilityParameters( ReachabilityParameters.filterDispositions(question.getActions().getDispositions()), forbiddenTransitNodes, finalNodes, headerSpace, question.getIgnoreFilters(), question.getInvertSearch(), ipSpaceAssignment, question.getMaxTraces(), requiredTransitNodes); } DifferentialReachabilityAnswerer(Question question, IBatfish batfish); @Override TableAnswerElement answer(NetworkSnapshot snapshot); @Override TableAnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference); }
DifferentialReachabilityAnswerer extends Answerer { @VisibleForTesting DifferentialReachabilityParameters parameters( NetworkSnapshot snapshot, NetworkSnapshot reference) { DifferentialReachabilityQuestion question = (DifferentialReachabilityQuestion) _question; PacketHeaderConstraints headerConstraints = question.getHeaderConstraints(); SpecifierContext snapshotCtxt = _batfish.specifierContext(snapshot); SpecifierContext referenceCtxt = _batfish.specifierContext(reference); PathConstraints pathConstraints = createPathConstraints(question.getPathConstraints()); Set<String> forbiddenTransitNodes = Sets.union( pathConstraints.getForbiddenLocations().resolve(snapshotCtxt), pathConstraints.getForbiddenLocations().resolve(referenceCtxt)); Set<String> requiredTransitNodes = Sets.union( pathConstraints.getTransitLocations().resolve(snapshotCtxt), pathConstraints.getTransitLocations().resolve(referenceCtxt)); Set<Location> startLocations = Sets.intersection( resolveActiveLocations(pathConstraints.getStartLocation(), snapshotCtxt), resolveActiveLocations(pathConstraints.getStartLocation(), referenceCtxt)); if (startLocations.isEmpty()) { throw new BatfishException( "no matching startLocation is present and active in both snapshots"); } Set<String> finalNodes = Sets.union( pathConstraints.getEndLocation().resolve(snapshotCtxt), pathConstraints.getEndLocation().resolve(referenceCtxt)); IpSpaceAssignment ipSpaceAssignment = SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getSrcIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(startLocations, snapshotCtxt); IpSpace dstIps = firstNonNull( AclIpSpace.union( SpecifierFactories.getIpSpaceSpecifierOrDefault( headerConstraints.getDstIps(), InferFromLocationIpSpaceSpecifier.INSTANCE) .resolve(ImmutableSet.of(), snapshotCtxt).getEntries().stream() .map(Entry::getIpSpace) .collect(ImmutableList.toImmutableList())), UniverseIpSpace.INSTANCE); AclLineMatchExpr headerSpace = PacketHeaderConstraintsUtil.toAclLineMatchExpr( headerConstraints, UniverseIpSpace.INSTANCE, dstIps); return new DifferentialReachabilityParameters( ReachabilityParameters.filterDispositions(question.getActions().getDispositions()), forbiddenTransitNodes, finalNodes, headerSpace, question.getIgnoreFilters(), question.getInvertSearch(), ipSpaceAssignment, question.getMaxTraces(), requiredTransitNodes); } DifferentialReachabilityAnswerer(Question question, IBatfish batfish); @Override TableAnswerElement answer(NetworkSnapshot snapshot); @Override TableAnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference); static final String COL_FLOW; }