@Test public void testNeighborComputation() { Map<String, Configuration> configs = threeNodeIbgpNet(); Map<String, Map<String, BgpActivePeerConfig>> neighborMap = generateIbgpNeighbors(configs).asMap(); assertThat(neighborMap, hasEntry(equalTo("r1"), allOf(hasKey("r2"), hasKey("r3")))); assertThat(neighborMap, hasEntry(equalTo("r2"), hasKey("r1"))); assertThat(neighborMap, hasEntry(equalTo("r3"), hasKey("r1"))); assertThat(neighborMap.get("r1").get("r2").getLocalIp(), equalTo(Ip.parse("1.1.2.1"))); assertThat(neighborMap.get("r1").get("r3").getLocalIp(), equalTo(Ip.parse("1.1.3.1"))); }
@VisibleForTesting @Nonnull static Table2<String, String, BgpActivePeerConfig> generateIbgpNeighbors( Map<String, Configuration> configurations) { Map<String, Set<Ip>> ips = new HashMap<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String hostname = entry.getKey(); Configuration conf = entry.getValue(); BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p == null) { continue; } for (BgpActivePeerConfig n : p.getActiveNeighbors().values()) { if (n.getLocalAs() == null || n.getRemoteAsns().isEmpty()) { continue; } if (n.getRemoteAsns().equals(LongSpace.of(n.getLocalAs()))) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp()); } } } Table2<String, String, BgpActivePeerConfig> neighbors = new Table2<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String localHostname = entry.getKey(); BgpProcess proc = entry.getValue().getDefaultVrf().getBgpProcess(); if (proc == null) { continue; } for (Entry<Prefix, BgpActivePeerConfig> entry2 : proc.getActiveNeighbors().entrySet()) { Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue(); if (localBgpConfig.getLocalAs() == null || localBgpConfig.getRemoteAsns().isEmpty()) { continue; } if (!localBgpConfig.getRemoteAsns().equals(LongSpace.of(localBgpConfig.getLocalAs()))) { continue; } for (Entry<String, Set<Ip>> ipEntry : ips.entrySet()) { String candidateHostname = ipEntry.getKey(); Set<Ip> candidateIps = ipEntry.getValue(); for (Ip candidateLocalIp : candidateIps) { if (!localHostname.equals(candidateHostname) && remotePrefix.containsIp(candidateLocalIp)) { neighbors.put(localHostname, candidateHostname, localBgpConfig); } } } } } return neighbors; }
Graph { @VisibleForTesting @Nonnull static Table2<String, String, BgpActivePeerConfig> generateIbgpNeighbors( Map<String, Configuration> configurations) { Map<String, Set<Ip>> ips = new HashMap<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String hostname = entry.getKey(); Configuration conf = entry.getValue(); BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p == null) { continue; } for (BgpActivePeerConfig n : p.getActiveNeighbors().values()) { if (n.getLocalAs() == null || n.getRemoteAsns().isEmpty()) { continue; } if (n.getRemoteAsns().equals(LongSpace.of(n.getLocalAs()))) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp()); } } } Table2<String, String, BgpActivePeerConfig> neighbors = new Table2<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String localHostname = entry.getKey(); BgpProcess proc = entry.getValue().getDefaultVrf().getBgpProcess(); if (proc == null) { continue; } for (Entry<Prefix, BgpActivePeerConfig> entry2 : proc.getActiveNeighbors().entrySet()) { Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue(); if (localBgpConfig.getLocalAs() == null || localBgpConfig.getRemoteAsns().isEmpty()) { continue; } if (!localBgpConfig.getRemoteAsns().equals(LongSpace.of(localBgpConfig.getLocalAs()))) { continue; } for (Entry<String, Set<Ip>> ipEntry : ips.entrySet()) { String candidateHostname = ipEntry.getKey(); Set<Ip> candidateIps = ipEntry.getValue(); for (Ip candidateLocalIp : candidateIps) { if (!localHostname.equals(candidateHostname) && remotePrefix.containsIp(candidateLocalIp)) { neighbors.put(localHostname, candidateHostname, localBgpConfig); } } } } } return neighbors; } }
Graph { @VisibleForTesting @Nonnull static Table2<String, String, BgpActivePeerConfig> generateIbgpNeighbors( Map<String, Configuration> configurations) { Map<String, Set<Ip>> ips = new HashMap<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String hostname = entry.getKey(); Configuration conf = entry.getValue(); BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p == null) { continue; } for (BgpActivePeerConfig n : p.getActiveNeighbors().values()) { if (n.getLocalAs() == null || n.getRemoteAsns().isEmpty()) { continue; } if (n.getRemoteAsns().equals(LongSpace.of(n.getLocalAs()))) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp()); } } } Table2<String, String, BgpActivePeerConfig> neighbors = new Table2<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String localHostname = entry.getKey(); BgpProcess proc = entry.getValue().getDefaultVrf().getBgpProcess(); if (proc == null) { continue; } for (Entry<Prefix, BgpActivePeerConfig> entry2 : proc.getActiveNeighbors().entrySet()) { Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue(); if (localBgpConfig.getLocalAs() == null || localBgpConfig.getRemoteAsns().isEmpty()) { continue; } if (!localBgpConfig.getRemoteAsns().equals(LongSpace.of(localBgpConfig.getLocalAs()))) { continue; } for (Entry<String, Set<Ip>> ipEntry : ips.entrySet()) { String candidateHostname = ipEntry.getKey(); Set<Ip> candidateIps = ipEntry.getValue(); for (Ip candidateLocalIp : candidateIps) { if (!localHostname.equals(candidateHostname) && remotePrefix.containsIp(candidateLocalIp)) { neighbors.put(localHostname, candidateHostname, localBgpConfig); } } } } } return neighbors; } Graph(IBatfish batfish, NetworkSnapshot snapshot);  Graph(IBatfish batfish, NetworkSnapshot snapshot, boolean bddBasedAnalysis);  Graph(
      IBatfish batfish, NetworkSnapshot snapshot, @Nullable Map<String, Configuration> configs);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers,
      @Nullable Set<CommunitySetExpr> communities,
      @Nullable Set<String> asPathRegexes);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers,
      @Nullable Set<CommunitySetExpr> communities,
      @Nullable Set<String> asPathRegexes,
      boolean bddBasedAnalysis); }
Graph { @VisibleForTesting @Nonnull static Table2<String, String, BgpActivePeerConfig> generateIbgpNeighbors( Map<String, Configuration> configurations) { Map<String, Set<Ip>> ips = new HashMap<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String hostname = entry.getKey(); Configuration conf = entry.getValue(); BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p == null) { continue; } for (BgpActivePeerConfig n : p.getActiveNeighbors().values()) { if (n.getLocalAs() == null || n.getRemoteAsns().isEmpty()) { continue; } if (n.getRemoteAsns().equals(LongSpace.of(n.getLocalAs()))) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp()); } } } Table2<String, String, BgpActivePeerConfig> neighbors = new Table2<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String localHostname = entry.getKey(); BgpProcess proc = entry.getValue().getDefaultVrf().getBgpProcess(); if (proc == null) { continue; } for (Entry<Prefix, BgpActivePeerConfig> entry2 : proc.getActiveNeighbors().entrySet()) { Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue(); if (localBgpConfig.getLocalAs() == null || localBgpConfig.getRemoteAsns().isEmpty()) { continue; } if (!localBgpConfig.getRemoteAsns().equals(LongSpace.of(localBgpConfig.getLocalAs()))) { continue; } for (Entry<String, Set<Ip>> ipEntry : ips.entrySet()) { String candidateHostname = ipEntry.getKey(); Set<Ip> candidateIps = ipEntry.getValue(); for (Ip candidateLocalIp : candidateIps) { if (!localHostname.equals(candidateHostname) && remotePrefix.containsIp(candidateLocalIp)) { neighbors.put(localHostname, candidateHostname, localBgpConfig); } } } } } return neighbors; } Graph(IBatfish batfish, NetworkSnapshot snapshot);  Graph(IBatfish batfish, NetworkSnapshot snapshot, boolean bddBasedAnalysis);  Graph(
      IBatfish batfish, NetworkSnapshot snapshot, @Nullable Map<String, Configuration> configs);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers,
      @Nullable Set<CommunitySetExpr> communities,
      @Nullable Set<String> asPathRegexes);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers,
      @Nullable Set<CommunitySetExpr> communities,
      @Nullable Set<String> asPathRegexes,
      boolean bddBasedAnalysis); NetworkSnapshot getSnapshot(); boolean isExternal(GraphEdge ge); boolean hasStaticRouteWithDynamicNextHop(); @Nullable static RoutingPolicy findCommonRoutingPolicy(Configuration conf, Protocol proto); static Set<Prefix> getOriginatedNetworks(Configuration conf); static Set<Prefix> getOriginatedNetworks(Configuration conf, Protocol proto); BgpSendType peerType(GraphEdge ge); Set<String> getDomain(String router); Set<CommunityVar> getAllCommunities(); boolean getBddBasedAnalysis(); SortedMap<CommunityVar, List<CommunityVar>> getCommunityDependencies(); Map<String, String> getNamedCommunities(); RegexAtomicPredicates<CommunityVar> getCommunityAtomicPredicates(); RegexAtomicPredicates<SymbolicAsPathRegex> getAsPathRegexAtomicPredicates(); Set<CommunityVar> findAllCommunities(); Set<CommunityVar> findAllCommunities(String router); Map<String, String> findNamedCommunities(); Set<Protocol> findRedistributedProtocols(
      Configuration conf, RoutingPolicy pol, Protocol p); long findRouterId(GraphEdge ge, Protocol proto); boolean isInterfaceActive(Protocol proto, Interface iface); boolean isEdgeUsed(Configuration conf, Protocol proto, GraphEdge ge); boolean isHost(String router); boolean isLoopback(GraphEdge ge); BgpActivePeerConfig findBgpNeighbor(GraphEdge e); @Nullable RoutingPolicy findImportRoutingPolicy(String router, Protocol proto, GraphEdge ge); @Nullable RoutingPolicy findExportRoutingPolicy(String router, Protocol proto, GraphEdge ge); @Override String toString(); Map<String, String> getRouteReflectorParent(); Map<String, Set<String>> getRouteReflectorClients(); Map<String, Integer> getOriginatorId(); Map<GraphEdge, BgpActivePeerConfig> getEbgpNeighbors(); Map<GraphEdge, BgpActivePeerConfig> getIbgpNeighbors(); Table2<String, String, List<StaticRoute>> getStaticRoutes(); Map<String, Set<Long>> getAreaIds(); Map<String, Configuration> getConfigurations(); Map<String, Set<String>> getNeighbors(); Map<String, List<GraphEdge>> getEdgeMap(); Map<GraphEdge, GraphEdge> getOtherEnd(); IBatfish getBatfish(); Set<GraphEdge> getAllRealEdges(); Set<GraphEdge> getAllEdges(); Set<String> getRouters(); }
Graph { @VisibleForTesting @Nonnull static Table2<String, String, BgpActivePeerConfig> generateIbgpNeighbors( Map<String, Configuration> configurations) { Map<String, Set<Ip>> ips = new HashMap<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String hostname = entry.getKey(); Configuration conf = entry.getValue(); BgpProcess p = conf.getDefaultVrf().getBgpProcess(); if (p == null) { continue; } for (BgpActivePeerConfig n : p.getActiveNeighbors().values()) { if (n.getLocalAs() == null || n.getRemoteAsns().isEmpty()) { continue; } if (n.getRemoteAsns().equals(LongSpace.of(n.getLocalAs()))) { ips.computeIfAbsent(hostname, key -> new HashSet<>()).add(n.getLocalIp()); } } } Table2<String, String, BgpActivePeerConfig> neighbors = new Table2<>(); for (Entry<String, Configuration> entry : configurations.entrySet()) { String localHostname = entry.getKey(); BgpProcess proc = entry.getValue().getDefaultVrf().getBgpProcess(); if (proc == null) { continue; } for (Entry<Prefix, BgpActivePeerConfig> entry2 : proc.getActiveNeighbors().entrySet()) { Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue(); if (localBgpConfig.getLocalAs() == null || localBgpConfig.getRemoteAsns().isEmpty()) { continue; } if (!localBgpConfig.getRemoteAsns().equals(LongSpace.of(localBgpConfig.getLocalAs()))) { continue; } for (Entry<String, Set<Ip>> ipEntry : ips.entrySet()) { String candidateHostname = ipEntry.getKey(); Set<Ip> candidateIps = ipEntry.getValue(); for (Ip candidateLocalIp : candidateIps) { if (!localHostname.equals(candidateHostname) && remotePrefix.containsIp(candidateLocalIp)) { neighbors.put(localHostname, candidateHostname, localBgpConfig); } } } } } return neighbors; } Graph(IBatfish batfish, NetworkSnapshot snapshot);  Graph(IBatfish batfish, NetworkSnapshot snapshot, boolean bddBasedAnalysis);  Graph(
      IBatfish batfish, NetworkSnapshot snapshot, @Nullable Map<String, Configuration> configs);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers,
      @Nullable Set<CommunitySetExpr> communities,
      @Nullable Set<String> asPathRegexes);  Graph(
      IBatfish batfish,
      NetworkSnapshot snapshot,
      @Nullable Map<String, Configuration> configs,
      @Nullable Set<String> routers,
      @Nullable Set<CommunitySetExpr> communities,
      @Nullable Set<String> asPathRegexes,
      boolean bddBasedAnalysis); NetworkSnapshot getSnapshot(); boolean isExternal(GraphEdge ge); boolean hasStaticRouteWithDynamicNextHop(); @Nullable static RoutingPolicy findCommonRoutingPolicy(Configuration conf, Protocol proto); static Set<Prefix> getOriginatedNetworks(Configuration conf); static Set<Prefix> getOriginatedNetworks(Configuration conf, Protocol proto); BgpSendType peerType(GraphEdge ge); Set<String> getDomain(String router); Set<CommunityVar> getAllCommunities(); boolean getBddBasedAnalysis(); SortedMap<CommunityVar, List<CommunityVar>> getCommunityDependencies(); Map<String, String> getNamedCommunities(); RegexAtomicPredicates<CommunityVar> getCommunityAtomicPredicates(); RegexAtomicPredicates<SymbolicAsPathRegex> getAsPathRegexAtomicPredicates(); Set<CommunityVar> findAllCommunities(); Set<CommunityVar> findAllCommunities(String router); Map<String, String> findNamedCommunities(); Set<Protocol> findRedistributedProtocols(
      Configuration conf, RoutingPolicy pol, Protocol p); long findRouterId(GraphEdge ge, Protocol proto); boolean isInterfaceActive(Protocol proto, Interface iface); boolean isEdgeUsed(Configuration conf, Protocol proto, GraphEdge ge); boolean isHost(String router); boolean isLoopback(GraphEdge ge); BgpActivePeerConfig findBgpNeighbor(GraphEdge e); @Nullable RoutingPolicy findImportRoutingPolicy(String router, Protocol proto, GraphEdge ge); @Nullable RoutingPolicy findExportRoutingPolicy(String router, Protocol proto, GraphEdge ge); @Override String toString(); Map<String, String> getRouteReflectorParent(); Map<String, Set<String>> getRouteReflectorClients(); Map<String, Integer> getOriginatorId(); Map<GraphEdge, BgpActivePeerConfig> getEbgpNeighbors(); Map<GraphEdge, BgpActivePeerConfig> getIbgpNeighbors(); Table2<String, String, List<StaticRoute>> getStaticRoutes(); Map<String, Set<Long>> getAreaIds(); Map<String, Configuration> getConfigurations(); Map<String, Set<String>> getNeighbors(); Map<String, List<GraphEdge>> getEdgeMap(); Map<GraphEdge, GraphEdge> getOtherEnd(); IBatfish getBatfish(); Set<GraphEdge> getAllRealEdges(); Set<GraphEdge> getAllEdges(); Set<String> getRouters(); static final String BGP_COMMON_FILTER_LIST_NAME; }