@Test public void testPostProcessInterfaceDependenciesBind() { NetworkFactory nf = new NetworkFactory(); Configuration c1 = nf.configurationBuilder() .setHostname("c1") .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .build(); Vrf vrf = nf.vrfBuilder().setOwner(c1).setName(Configuration.DEFAULT_VRF_NAME).build(); Interface.Builder ib = nf.interfaceBuilder().setOwner(c1).setVrf(vrf); ib.setName("eth0").setActive(false).build(); ib.setName("eth1") .setActive(true) .setDependencies(ImmutableSet.of(new Dependency("eth0", DependencyType.BIND))) .build(); ib.setName("eth2") .setActive(true) .setDependencies(ImmutableSet.of(new Dependency("eth1", DependencyType.BIND))) .build(); ib.setName("eth9").setDependencies(ImmutableSet.of()).setActive(true).build(); ImmutableSet<String> activeIfaces = ImmutableSet.of("eth9"); ImmutableSet<String> inactiveIfaces = ImmutableSet.of("eth0", "eth1", "eth2"); postProcessInterfaceDependencies(ImmutableMap.of("c1", c1)); activeIfaces.forEach( name -> assertThat(c1.getAllInterfaces().get(name).getActive(), equalTo(true))); inactiveIfaces.forEach( name -> assertThat(c1.getAllInterfaces().get(name).getActive(), equalTo(false))); }
@VisibleForTesting static void postProcessInterfaceDependencies(Map<String, Configuration> configurations) { configurations .values() .forEach( config -> { Map<String, Interface> allInterfaces = config.getAllInterfaces(); Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); allInterfaces.keySet().forEach(graph::addVertex); allInterfaces .values() .forEach( iface -> iface .getDependencies() .forEach( dependency -> { graph.addVertex(dependency.getInterfaceName()); graph.addEdge( dependency.getInterfaceName(), iface.getName()); })); for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext(); ) { String ifaceName = iterator.next(); @Nullable Interface iface = allInterfaces.get(ifaceName); if (iface == null) { continue; } deactivateInterfaceIfNeeded(iface); } }); }
Batfish extends PluginConsumer implements IBatfish { @VisibleForTesting static void postProcessInterfaceDependencies(Map<String, Configuration> configurations) { configurations .values() .forEach( config -> { Map<String, Interface> allInterfaces = config.getAllInterfaces(); Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); allInterfaces.keySet().forEach(graph::addVertex); allInterfaces .values() .forEach( iface -> iface .getDependencies() .forEach( dependency -> { graph.addVertex(dependency.getInterfaceName()); graph.addEdge( dependency.getInterfaceName(), iface.getName()); })); for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext(); ) { String ifaceName = iterator.next(); @Nullable Interface iface = allInterfaces.get(ifaceName); if (iface == null) { continue; } deactivateInterfaceIfNeeded(iface); } }); } }
Batfish extends PluginConsumer implements IBatfish { @VisibleForTesting static void postProcessInterfaceDependencies(Map<String, Configuration> configurations) { configurations .values() .forEach( config -> { Map<String, Interface> allInterfaces = config.getAllInterfaces(); Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); allInterfaces.keySet().forEach(graph::addVertex); allInterfaces .values() .forEach( iface -> iface .getDependencies() .forEach( dependency -> { graph.addVertex(dependency.getInterfaceName()); graph.addEdge( dependency.getInterfaceName(), iface.getName()); })); for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext(); ) { String ifaceName = iterator.next(); @Nullable Interface iface = allInterfaces.get(ifaceName); if (iface == null) { continue; } deactivateInterfaceIfNeeded(iface); } }); } Batfish(
      Settings settings,
      Cache<NetworkSnapshot, SortedMap<String, Configuration>> cachedConfigurations,
      Cache<NetworkSnapshot, DataPlane> cachedDataPlanes,
      Map<NetworkSnapshot, SortedMap<String, BgpAdvertisementsByVrf>> cachedEnvironmentBgpTables,
      Cache<NetworkSnapshot, Map<String, VendorConfiguration>> cachedVendorConfigurations,
      @Nullable StorageProvider alternateStorageProvider,
      @Nullable IdResolver alternateIdResolver); }
Batfish extends PluginConsumer implements IBatfish { @VisibleForTesting static void postProcessInterfaceDependencies(Map<String, Configuration> configurations) { configurations .values() .forEach( config -> { Map<String, Interface> allInterfaces = config.getAllInterfaces(); Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); allInterfaces.keySet().forEach(graph::addVertex); allInterfaces .values() .forEach( iface -> iface .getDependencies() .forEach( dependency -> { graph.addVertex(dependency.getInterfaceName()); graph.addEdge( dependency.getInterfaceName(), iface.getName()); })); for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext(); ) { String ifaceName = iterator.next(); @Nullable Interface iface = allInterfaces.get(ifaceName); if (iface == null) { continue; } deactivateInterfaceIfNeeded(iface); } }); } Batfish(
      Settings settings,
      Cache<NetworkSnapshot, SortedMap<String, Configuration>> cachedConfigurations,
      Cache<NetworkSnapshot, DataPlane> cachedDataPlanes,
      Map<NetworkSnapshot, SortedMap<String, BgpAdvertisementsByVrf>> cachedEnvironmentBgpTables,
      Cache<NetworkSnapshot, Map<String, VendorConfiguration>> cachedVendorConfigurations,
      @Nullable StorageProvider alternateStorageProvider,
      @Nullable IdResolver alternateIdResolver); static Flattener flatten(
      String input,
      BatfishLogger logger,
      Settings settings,
      Warnings warnings,
      ConfigurationFormat format,
      String header); static void logWarnings(BatfishLogger logger, Warnings warnings); static ParserRuleContext parse(
      BatfishCombinedParser<?, ?> parser, BatfishLogger logger, GrammarSettings settings); Answer answer(); static Warnings buildWarnings(Settings settings); @Override DataPlaneAnswerElement computeDataPlane(NetworkSnapshot snapshot); @Override boolean debugFlagEnabled(String flag); @Override Map<Location, LocationInfo> getLocationInfo(NetworkSnapshot snapshot); Map<String, Configuration> getConfigurations(
      Map<String, VendorConfiguration> vendorConfigurations,
      SnapshotRuntimeData runtimeData,
      ConvertConfigurationAnswerElement answerElement); @Override NetworkId getContainerName(); @Override DataPlanePlugin getDataPlanePlugin(); @Override Environment getEnvironment(); @Override BatfishLogger getLogger(); @Override NodeRolesData getNodeRolesData(); @Override Optional<NodeRoleDimension> getNodeRoleDimension(@Nullable String dimension); @Override Map<String, String> getQuestionTemplates(boolean verbose); @Override @Nullable ReferenceLibrary getReferenceLibraryData(); Settings getSettings(); @Override ImmutableConfiguration getSettingsConfiguration(); @Override NetworkSnapshot getSnapshot(); @Override NetworkSnapshot getReferenceSnapshot(); @Override String getTaskId(); String getTerminatingExceptionMessage(); @Nonnull @Override TopologyProvider getTopologyProvider(); @Override PluginClientType getType(); @Override InitInfoAnswerElement initInfo(
      NetworkSnapshot snapshot, boolean summary, boolean verboseError); @Override InitInfoAnswerElement initInfoBgpAdvertisements(
      NetworkSnapshot snapshot, boolean summary, boolean verboseError); @Override SortedMap<String, Configuration> loadConfigurations(NetworkSnapshot snapshot); @Override ConvertConfigurationAnswerElement loadConvertConfigurationAnswerElementOrReparse(
      NetworkSnapshot snapshot); @Override DataPlane loadDataPlane(NetworkSnapshot snapshot); @Override SortedMap<String, BgpAdvertisementsByVrf> loadEnvironmentBgpTables(
      NetworkSnapshot snapshot); ParseEnvironmentBgpTablesAnswerElement loadParseEnvironmentBgpTablesAnswerElement(
      NetworkSnapshot snapshot); @Override ParseVendorConfigurationAnswerElement loadParseVendorConfigurationAnswerElement(
      NetworkSnapshot snapshot); @Override Map<String, VendorConfiguration> loadVendorConfigurations(NetworkSnapshot snapshot); @Override AtomicInteger newBatch(String description, int jobs); @VisibleForTesting @Nonnull static AwsConfiguration parseAwsConfigurations(
      Map<String, String> configurationData, ParseVendorConfigurationAnswerElement pvcae); @Override Set<BgpAdvertisement> loadExternalBgpAnnouncements(
      NetworkSnapshot snapshot, Map<String, Configuration> configurations); @Override SortedMap<Flow, List<Trace>> buildFlows(
      NetworkSnapshot snapshot, Set<Flow> flows, boolean ignoreFilters); @Override TracerouteEngine getTracerouteEngine(NetworkSnapshot snapshot); @Override @Nullable String readExternalBgpAnnouncementsFile(NetworkSnapshot snapshot); @Override void registerAnswerer(
      String questionName,
      String questionClassName,
      BiFunction<Question, IBatfish, Answerer> answererCreator); @Override void registerBgpTablePlugin(BgpTableFormat format, BgpTablePlugin bgpTablePlugin); @Override void registerExternalBgpAdvertisementPlugin(
      ExternalBgpAdvertisementPlugin externalBgpAdvertisementPlugin); @MustBeClosed @Nonnull @Override InputStream getNetworkObject(NetworkId networkId, String key); @MustBeClosed @Nonnull @Override InputStream getSnapshotInputObject(NetworkSnapshot snapshot, String key); Answer run(NetworkSnapshot snapshot); @Override void registerDataPlanePlugin(DataPlanePlugin plugin, String name); void setTerminatingExceptionMessage(String terminatingExceptionMessage); @Override SpecifierContext specifierContext(NetworkSnapshot networkSnapshot); @Override BidirectionalReachabilityResult bidirectionalReachability(
      NetworkSnapshot snapshot, BDDPacket bddPacket, ReachabilityParameters parameters); @Override AnswerElement standard(
      NetworkSnapshot snapshot, ReachabilityParameters reachabilityParameters); AnswerElement bddSingleReachability(
      NetworkSnapshot snapshot, ReachabilityParameters parameters); @Override Set<Flow> bddLoopDetection(NetworkSnapshot snapshot); @Override Set<Flow> bddMultipathConsistency(
      NetworkSnapshot snapshot, MultipathConsistencyParameters parameters); @Nonnull IpSpaceAssignment getAllSourcesInferFromLocationIpSpaceAssignment(
      NetworkSnapshot snapshot); BDDReachabilityAnalysis getBddReachabilityAnalysis(
      NetworkSnapshot snapshot,
      BDDPacket pkt,
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions,
      boolean ignoreFilters,
      boolean useInterfaceRoots); @Override DifferentialReachabilityResult bddDifferentialReachability(
      NetworkSnapshot snapshot,
      NetworkSnapshot reference,
      DifferentialReachabilityParameters parameters); @Override @Nullable Answerer createAnswerer(@Nonnull Question question); }
Batfish extends PluginConsumer implements IBatfish { @VisibleForTesting static void postProcessInterfaceDependencies(Map<String, Configuration> configurations) { configurations .values() .forEach( config -> { Map<String, Interface> allInterfaces = config.getAllInterfaces(); Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); allInterfaces.keySet().forEach(graph::addVertex); allInterfaces .values() .forEach( iface -> iface .getDependencies() .forEach( dependency -> { graph.addVertex(dependency.getInterfaceName()); graph.addEdge( dependency.getInterfaceName(), iface.getName()); })); for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext(); ) { String ifaceName = iterator.next(); @Nullable Interface iface = allInterfaces.get(ifaceName); if (iface == null) { continue; } deactivateInterfaceIfNeeded(iface); } }); } Batfish(
      Settings settings,
      Cache<NetworkSnapshot, SortedMap<String, Configuration>> cachedConfigurations,
      Cache<NetworkSnapshot, DataPlane> cachedDataPlanes,
      Map<NetworkSnapshot, SortedMap<String, BgpAdvertisementsByVrf>> cachedEnvironmentBgpTables,
      Cache<NetworkSnapshot, Map<String, VendorConfiguration>> cachedVendorConfigurations,
      @Nullable StorageProvider alternateStorageProvider,
      @Nullable IdResolver alternateIdResolver); static Flattener flatten(
      String input,
      BatfishLogger logger,
      Settings settings,
      Warnings warnings,
      ConfigurationFormat format,
      String header); static void logWarnings(BatfishLogger logger, Warnings warnings); static ParserRuleContext parse(
      BatfishCombinedParser<?, ?> parser, BatfishLogger logger, GrammarSettings settings); Answer answer(); static Warnings buildWarnings(Settings settings); @Override DataPlaneAnswerElement computeDataPlane(NetworkSnapshot snapshot); @Override boolean debugFlagEnabled(String flag); @Override Map<Location, LocationInfo> getLocationInfo(NetworkSnapshot snapshot); Map<String, Configuration> getConfigurations(
      Map<String, VendorConfiguration> vendorConfigurations,
      SnapshotRuntimeData runtimeData,
      ConvertConfigurationAnswerElement answerElement); @Override NetworkId getContainerName(); @Override DataPlanePlugin getDataPlanePlugin(); @Override Environment getEnvironment(); @Override BatfishLogger getLogger(); @Override NodeRolesData getNodeRolesData(); @Override Optional<NodeRoleDimension> getNodeRoleDimension(@Nullable String dimension); @Override Map<String, String> getQuestionTemplates(boolean verbose); @Override @Nullable ReferenceLibrary getReferenceLibraryData(); Settings getSettings(); @Override ImmutableConfiguration getSettingsConfiguration(); @Override NetworkSnapshot getSnapshot(); @Override NetworkSnapshot getReferenceSnapshot(); @Override String getTaskId(); String getTerminatingExceptionMessage(); @Nonnull @Override TopologyProvider getTopologyProvider(); @Override PluginClientType getType(); @Override InitInfoAnswerElement initInfo(
      NetworkSnapshot snapshot, boolean summary, boolean verboseError); @Override InitInfoAnswerElement initInfoBgpAdvertisements(
      NetworkSnapshot snapshot, boolean summary, boolean verboseError); @Override SortedMap<String, Configuration> loadConfigurations(NetworkSnapshot snapshot); @Override ConvertConfigurationAnswerElement loadConvertConfigurationAnswerElementOrReparse(
      NetworkSnapshot snapshot); @Override DataPlane loadDataPlane(NetworkSnapshot snapshot); @Override SortedMap<String, BgpAdvertisementsByVrf> loadEnvironmentBgpTables(
      NetworkSnapshot snapshot); ParseEnvironmentBgpTablesAnswerElement loadParseEnvironmentBgpTablesAnswerElement(
      NetworkSnapshot snapshot); @Override ParseVendorConfigurationAnswerElement loadParseVendorConfigurationAnswerElement(
      NetworkSnapshot snapshot); @Override Map<String, VendorConfiguration> loadVendorConfigurations(NetworkSnapshot snapshot); @Override AtomicInteger newBatch(String description, int jobs); @VisibleForTesting @Nonnull static AwsConfiguration parseAwsConfigurations(
      Map<String, String> configurationData, ParseVendorConfigurationAnswerElement pvcae); @Override Set<BgpAdvertisement> loadExternalBgpAnnouncements(
      NetworkSnapshot snapshot, Map<String, Configuration> configurations); @Override SortedMap<Flow, List<Trace>> buildFlows(
      NetworkSnapshot snapshot, Set<Flow> flows, boolean ignoreFilters); @Override TracerouteEngine getTracerouteEngine(NetworkSnapshot snapshot); @Override @Nullable String readExternalBgpAnnouncementsFile(NetworkSnapshot snapshot); @Override void registerAnswerer(
      String questionName,
      String questionClassName,
      BiFunction<Question, IBatfish, Answerer> answererCreator); @Override void registerBgpTablePlugin(BgpTableFormat format, BgpTablePlugin bgpTablePlugin); @Override void registerExternalBgpAdvertisementPlugin(
      ExternalBgpAdvertisementPlugin externalBgpAdvertisementPlugin); @MustBeClosed @Nonnull @Override InputStream getNetworkObject(NetworkId networkId, String key); @MustBeClosed @Nonnull @Override InputStream getSnapshotInputObject(NetworkSnapshot snapshot, String key); Answer run(NetworkSnapshot snapshot); @Override void registerDataPlanePlugin(DataPlanePlugin plugin, String name); void setTerminatingExceptionMessage(String terminatingExceptionMessage); @Override SpecifierContext specifierContext(NetworkSnapshot networkSnapshot); @Override BidirectionalReachabilityResult bidirectionalReachability(
      NetworkSnapshot snapshot, BDDPacket bddPacket, ReachabilityParameters parameters); @Override AnswerElement standard(
      NetworkSnapshot snapshot, ReachabilityParameters reachabilityParameters); AnswerElement bddSingleReachability(
      NetworkSnapshot snapshot, ReachabilityParameters parameters); @Override Set<Flow> bddLoopDetection(NetworkSnapshot snapshot); @Override Set<Flow> bddMultipathConsistency(
      NetworkSnapshot snapshot, MultipathConsistencyParameters parameters); @Nonnull IpSpaceAssignment getAllSourcesInferFromLocationIpSpaceAssignment(
      NetworkSnapshot snapshot); BDDReachabilityAnalysis getBddReachabilityAnalysis(
      NetworkSnapshot snapshot,
      BDDPacket pkt,
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions,
      boolean ignoreFilters,
      boolean useInterfaceRoots); @Override DifferentialReachabilityResult bddDifferentialReachability(
      NetworkSnapshot snapshot,
      NetworkSnapshot reference,
      DifferentialReachabilityParameters parameters); @Override @Nullable Answerer createAnswerer(@Nonnull Question question);  }