@Test public void testComputeArpFalseDestIp() { String c1 = "c1"; String v1 = "v1"; String i1 = "i1"; AbstractRoute ifaceRoute = new ConnectedRoute(P1, i1); Map<String, Map<String, Fib>> fibs = ImmutableMap.of( c1, ImmutableMap.of( v1, MockFib.builder().setMatchingIps(ImmutableMap.of(P1, P1.toIpSpace())).build())); Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWhereDstIpCanBeArpIp = ImmutableMap.of(c1, ImmutableMap.of(v1, ImmutableMap.of(i1, ImmutableSet.of(ifaceRoute)))); Map<String, Map<String, IpSpace>> someoneReplies = ImmutableMap.of(c1, ImmutableMap.of(i1, P1.getEndIp().toIpSpace())); Map<String, Map<String, Map<String, IpSpace>>> result = computeArpFalseDestIp(computeMatchingIps(fibs), routesWhereDstIpCanBeArpIp, someoneReplies); 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), not(containsIp(P1.getEndIp())))))); assertThat( result, hasEntry( equalTo(c1), hasEntry(equalTo(v1), hasEntry(equalTo(i1), not(containsIp(P2.getEndIp())))))); }
@VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeArpFalseDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWhereDstIpCanBeArpIp, Map<String, Map<String, IpSpace>> someoneReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpFalseDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWhereDstIpCanBeArpIp, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); Map<String, IpSpace> someoneRepliesNode = someoneReplies.getOrDefault(hostname, ImmutableMap.of()); 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(entry -> !entry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .collect( ImmutableMap.toImmutableMap( Entry::getKey , ifaceEntry -> { String outInterface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); IpSpace someoneRepliesIface = someoneRepliesNode.getOrDefault( outInterface, EmptyIpSpace.INSTANCE); IpSpace ipsRoutedOutInterface = computeRouteMatchConditions(routes, vrfMatchingIps); return AclIpSpace.rejecting(someoneRepliesIface) .thenPermitting(ipsRoutedOutInterface) .build(); })); }); }); } finally { span.finish(); } }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeArpFalseDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWhereDstIpCanBeArpIp, Map<String, Map<String, IpSpace>> someoneReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpFalseDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWhereDstIpCanBeArpIp, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); Map<String, IpSpace> someoneRepliesNode = someoneReplies.getOrDefault(hostname, ImmutableMap.of()); 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(entry -> !entry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .collect( ImmutableMap.toImmutableMap( Entry::getKey , ifaceEntry -> { String outInterface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); IpSpace someoneRepliesIface = someoneRepliesNode.getOrDefault( outInterface, EmptyIpSpace.INSTANCE); IpSpace ipsRoutedOutInterface = computeRouteMatchConditions(routes, vrfMatchingIps); return AclIpSpace.rejecting(someoneRepliesIface) .thenPermitting(ipsRoutedOutInterface) .build(); })); }); }); } finally { span.finish(); } } }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<String, IpSpace>>> computeArpFalseDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWhereDstIpCanBeArpIp, Map<String, Map<String, IpSpace>> someoneReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpFalseDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWhereDstIpCanBeArpIp, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); Map<String, IpSpace> someoneRepliesNode = someoneReplies.getOrDefault(hostname, ImmutableMap.of()); 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(entry -> !entry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .collect( ImmutableMap.toImmutableMap( Entry::getKey , ifaceEntry -> { String outInterface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); IpSpace someoneRepliesIface = someoneRepliesNode.getOrDefault( outInterface, EmptyIpSpace.INSTANCE); IpSpace ipsRoutedOutInterface = computeRouteMatchConditions(routes, vrfMatchingIps); return AclIpSpace.rejecting(someoneRepliesIface) .thenPermitting(ipsRoutedOutInterface) .build(); })); }); }); } 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>>> computeArpFalseDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWhereDstIpCanBeArpIp, Map<String, Map<String, IpSpace>> someoneReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpFalseDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWhereDstIpCanBeArpIp, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); Map<String, IpSpace> someoneRepliesNode = someoneReplies.getOrDefault(hostname, ImmutableMap.of()); 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(entry -> !entry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .collect( ImmutableMap.toImmutableMap( Entry::getKey , ifaceEntry -> { String outInterface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); IpSpace someoneRepliesIface = someoneRepliesNode.getOrDefault( outInterface, EmptyIpSpace.INSTANCE); IpSpace ipsRoutedOutInterface = computeRouteMatchConditions(routes, vrfMatchingIps); return AclIpSpace.rejecting(someoneRepliesIface) .thenPermitting(ipsRoutedOutInterface) .build(); })); }); }); } 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>>> computeArpFalseDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<String, Set<AbstractRoute>>>> routesWhereDstIpCanBeArpIp, Map<String, Map<String, IpSpace>> someoneReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpFalseDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWhereDstIpCanBeArpIp, Entry::getKey , nodeEntry -> { String hostname = nodeEntry.getKey(); Map<String, IpSpace> someoneRepliesNode = someoneReplies.getOrDefault(hostname, ImmutableMap.of()); 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(entry -> !entry.getKey().equals(Interface.NULL_INTERFACE_NAME)) .collect( ImmutableMap.toImmutableMap( Entry::getKey , ifaceEntry -> { String outInterface = ifaceEntry.getKey(); Set<AbstractRoute> routes = ifaceEntry.getValue(); IpSpace someoneRepliesIface = someoneRepliesNode.getOrDefault( outInterface, EmptyIpSpace.INSTANCE); IpSpace ipsRoutedOutInterface = computeRouteMatchConditions(routes, vrfMatchingIps); return AclIpSpace.rejecting(someoneRepliesIface) .thenPermitting(ipsRoutedOutInterface) .build(); })); }); }); } 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();  }