@Test public void testComputeIpsRoutedOutInterfaces() { String c1 = "c1"; String v1 = "v1"; String i1 = "i1"; ConnectedRoute r1 = new ConnectedRoute(P1, i1); StaticRoute nullRoute = StaticRoute.builder() .setNetwork(P2) .setNextHopInterface(Interface.NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build(); Map<String, Map<String, Fib>> fibs = ImmutableMap.of( c1, ImmutableMap.of( v1, MockFib.builder() .setMatchingIps(ImmutableMap.of(P1, P1.toIpSpace(), P2, P2.toIpSpace())) .build())); Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWithNextHop = ImmutableMap.of( c1, ImmutableMap.of( v1, ImmutableMap.of( i1, ImmutableSet.of(r1), Interface.NULL_INTERFACE_NAME, ImmutableSet.of(nullRoute)))); Map<String, Map<String, Map<String, IpSpace>>> result = computeIpsRoutedOutInterfaces(computeMatchingIps(fibs), routesWithNextHop); assertThat( result, hasEntry( equalTo(c1), hasEntry(equalTo(v1), hasEntry(equalTo(i1), containsIp(P1.getStartIp()))))); assertThat( result, hasEntry( equalTo(c1), hasEntry(equalTo(v1), hasEntry(equalTo(i1), containsIp(P1.getEndIp()))))); assertThat( result, hasEntry( equalTo(c1), hasEntry(equalTo(v1), hasEntry(equalTo(i1), not(containsIp(P2.getStartIp())))))); assertThat(result, hasEntry(equalTo(c1), not(hasKey(equalTo(Interface.NULL_INTERFACE_NAME))))); }
@VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeIpsRoutedOutInterfaces( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWithNextHop) { Span span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeIpsRoutedOutInterfaces") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithNextHop, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); return toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> { String vrf = vrfEntry.getKey(); Map<Prefix, IpSpace> vrfMatchingIps = matchingIps.get(hostname).get(vrf); return vrfEntry.getValue().entrySet().stream() .filter( ifaceEntry -> !ifaceEntry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .map( ifaceEntry -> { String iface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); return Maps.immutableEntry( iface, computeRouteMatchConditions(routes, vrfMatchingIps)); }) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)); }); }); } finally { span.finish(); } }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeIpsRoutedOutInterfaces( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWithNextHop) { Span span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeIpsRoutedOutInterfaces") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithNextHop, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); return toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> { String vrf = vrfEntry.getKey(); Map<Prefix, IpSpace> vrfMatchingIps = matchingIps.get(hostname).get(vrf); return vrfEntry.getValue().entrySet().stream() .filter( ifaceEntry -> !ifaceEntry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .map( ifaceEntry -> { String iface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); return Maps.immutableEntry( iface, computeRouteMatchConditions(routes, vrfMatchingIps)); }) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)); }); }); } finally { span.finish(); } } }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeIpsRoutedOutInterfaces( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWithNextHop) { Span span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeIpsRoutedOutInterfaces") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithNextHop, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); return toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> { String vrf = vrfEntry.getKey(); Map<Prefix, IpSpace> vrfMatchingIps = matchingIps.get(hostname).get(vrf); return vrfEntry.getValue().entrySet().stream() .filter( ifaceEntry -> !ifaceEntry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .map( ifaceEntry -> { String iface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); return Maps.immutableEntry( iface, computeRouteMatchConditions(routes, vrfMatchingIps)); }) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)); }); }); } finally { span.finish(); } } ForwardingAnalysisImpl(
      Map<String, Configuration> configurations,
      Map<String, Map<String, Fib>> fibs,
      Topology topology,
      Map<Location, LocationInfo> locationInfo); }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeIpsRoutedOutInterfaces( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWithNextHop) { Span span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeIpsRoutedOutInterfaces") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithNextHop, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); return toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> { String vrf = vrfEntry.getKey(); Map<Prefix, IpSpace> vrfMatchingIps = matchingIps.get(hostname).get(vrf); return vrfEntry.getValue().entrySet().stream() .filter( ifaceEntry -> !ifaceEntry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .map( ifaceEntry -> { String iface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); return Maps.immutableEntry( iface, computeRouteMatchConditions(routes, vrfMatchingIps)); }) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)); }); }); } finally { span.finish(); } } ForwardingAnalysisImpl(
      Map<String, Configuration> configurations,
      Map<String, Map<String, Fib>> fibs,
      Topology topology,
      Map<Location, LocationInfo> locationInfo); @Nonnull @Override Map<String, Map<String, Map<String, IpSpace>>> getAcceptsIps(); @Override Map<String, Map<String, IpSpace>> getArpReplies(); @Override Map<String, Map<String, Map<Edge, IpSpace>>> getArpTrueEdge(); @Override Map<String, Map<String, Map<String, IpSpace>>> getNextVrfIps(); @Override Map<String, Map<String, IpSpace>> getNullRoutedIps(); @Override Map<String, Map<String, IpSpace>> getRoutableIps(); @Override Map<String, Map<String, Map<String, IpSpace>>> getDeliveredToSubnet(); @Override Map<String, Map<String, Map<String, IpSpace>>> getExitsNetwork(); @Override Map<String, Map<String, Map<String, IpSpace>>> getNeighborUnreachable(); @Override Map<String, Map<String, Map<String, IpSpace>>> getInsufficientInfo(); }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeIpsRoutedOutInterfaces( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWithNextHop) { Span span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeIpsRoutedOutInterfaces") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithNextHop, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); return toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> { String vrf = vrfEntry.getKey(); Map<Prefix, IpSpace> vrfMatchingIps = matchingIps.get(hostname).get(vrf); return vrfEntry.getValue().entrySet().stream() .filter( ifaceEntry -> !ifaceEntry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .map( ifaceEntry -> { String iface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); return Maps.immutableEntry( iface, computeRouteMatchConditions(routes, vrfMatchingIps)); }) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)); }); }); } finally { span.finish(); } } ForwardingAnalysisImpl(
      Map<String, Configuration> configurations,
      Map<String, Map<String, Fib>> fibs,
      Topology topology,
      Map<Location, LocationInfo> locationInfo); @Nonnull @Override Map<String, Map<String, Map<String, IpSpace>>> getAcceptsIps(); @Override Map<String, Map<String, IpSpace>> getArpReplies(); @Override Map<String, Map<String, Map<Edge, IpSpace>>> getArpTrueEdge(); @Override Map<String, Map<String, Map<String, IpSpace>>> getNextVrfIps(); @Override Map<String, Map<String, IpSpace>> getNullRoutedIps(); @Override Map<String, Map<String, IpSpace>> getRoutableIps(); @Override Map<String, Map<String, Map<String, IpSpace>>> getDeliveredToSubnet(); @Override Map<String, Map<String, Map<String, IpSpace>>> getExitsNetwork(); @Override Map<String, Map<String, Map<String, IpSpace>>> getNeighborUnreachable(); @Override Map<String, Map<String, Map<String, IpSpace>>> getInsufficientInfo();  }