@Test public void testComputeArpTrueEdgeDestIp() { Configuration c1 = _cb.build(); Configuration c2 = _cb.build(); Vrf vrf1 = _vb.setOwner(c1).build(); Vrf vrf2 = _vb.setOwner(c2).build(); Interface i1 = _ib.setOwner(c1).setVrf(vrf1).build(); Ip i2Ip = Ip.create(P1.getStartIp().asLong() + 1); Interface i2 = _ib.setOwner(c2).setVrf(vrf2).build(); Map<String, Map<String, Fib>> fibs = ImmutableMap.of( c1.getHostname(), ImmutableMap.of( vrf1.getName(), MockFib.builder() .setMatchingIps( ImmutableMap.of( P1, AclIpSpace.rejecting(P1.getEndIp().toIpSpace()) .thenPermitting(P1.toIpSpace()) .build())) .build())); Edge edge = Edge.of(c1.getHostname(), i1.getName(), c2.getHostname(), i2.getName()); Map<String, Map<String, Map<Edge, Set<AbstractRoute>>>> routesWithDestIpEdge = ImmutableMap.of( c1.getHostname(), ImmutableMap.of( vrf1.getName(), ImmutableMap.of(edge, ImmutableSet.of(new ConnectedRoute(P1, i1.getName()))))); Map<String, Map<String, IpSpace>> arpReplies = ImmutableMap.of( c2.getHostname(), ImmutableMap.of( i2.getName(), AclIpSpace.permitting(i2Ip.toIpSpace()) .thenPermitting(P1.getEndIp().toIpSpace()) .build())); Map<String, Map<String, Map<Edge, IpSpace>>> result = computeArpTrueEdgeDestIp(computeMatchingIps(fibs), routesWithDestIpEdge, arpReplies); assertThat( result, hasEntry( equalTo(c1.getHostname()), hasEntry(equalTo(vrf1.getName()), hasEntry(equalTo(edge), containsIp(i2Ip))))); assertThat( result, hasEntry( equalTo(c1.getHostname()), hasEntry( equalTo(vrf1.getName()), hasEntry(equalTo(edge), not(containsIp(P1.getEndIp())))))); assertThat( result, hasEntry( equalTo(c1.getHostname()), hasEntry( equalTo(vrf1.getName()), hasEntry(equalTo(edge), not(containsIp(P1.getStartIp())))))); }
@VisibleForTesting static Map<String, Map<String, Map<Edge, IpSpace>>> computeArpTrueEdgeDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<Edge, Set<AbstractRoute>>>> routesWithDestIpEdge, Map<String, Map<String, IpSpace>> arpReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpTrueEdgeDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithDestIpEdge, Entry::getKey, nodeEntry -> toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> toImmutableMap( vrfEntry.getValue(), Entry::getKey, edgeEntry -> { Edge edge = edgeEntry.getKey(); Set<AbstractRoute> routes = edgeEntry.getValue(); String hostname = edge.getNode1(); String vrf = vrfEntry.getKey(); IpSpace dstIpMatchesSomeRoutePrefix = computeRouteMatchConditions( routes, matchingIps.get(hostname).get(vrf)); String recvNode = edge.getNode2(); String recvInterface = edge.getInt2(); IpSpace recvReplies = arpReplies.get(recvNode).get(recvInterface); return AclIpSpace.rejecting(dstIpMatchesSomeRoutePrefix.complement()) .thenPermitting(recvReplies) .build(); }))); } finally { span.finish(); } }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<Edge, IpSpace>>> computeArpTrueEdgeDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<Edge, Set<AbstractRoute>>>> routesWithDestIpEdge, Map<String, Map<String, IpSpace>> arpReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpTrueEdgeDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithDestIpEdge, Entry::getKey, nodeEntry -> toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> toImmutableMap( vrfEntry.getValue(), Entry::getKey, edgeEntry -> { Edge edge = edgeEntry.getKey(); Set<AbstractRoute> routes = edgeEntry.getValue(); String hostname = edge.getNode1(); String vrf = vrfEntry.getKey(); IpSpace dstIpMatchesSomeRoutePrefix = computeRouteMatchConditions( routes, matchingIps.get(hostname).get(vrf)); String recvNode = edge.getNode2(); String recvInterface = edge.getInt2(); IpSpace recvReplies = arpReplies.get(recvNode).get(recvInterface); return AclIpSpace.rejecting(dstIpMatchesSomeRoutePrefix.complement()) .thenPermitting(recvReplies) .build(); }))); } finally { span.finish(); } } }
ForwardingAnalysisImpl implements ForwardingAnalysis, Serializable { @VisibleForTesting static Map<String, Map<String, Map<Edge, IpSpace>>> computeArpTrueEdgeDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<Edge, Set<AbstractRoute>>>> routesWithDestIpEdge, Map<String, Map<String, IpSpace>> arpReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpTrueEdgeDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithDestIpEdge, Entry::getKey, nodeEntry -> toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> toImmutableMap( vrfEntry.getValue(), Entry::getKey, edgeEntry -> { Edge edge = edgeEntry.getKey(); Set<AbstractRoute> routes = edgeEntry.getValue(); String hostname = edge.getNode1(); String vrf = vrfEntry.getKey(); IpSpace dstIpMatchesSomeRoutePrefix = computeRouteMatchConditions( routes, matchingIps.get(hostname).get(vrf)); String recvNode = edge.getNode2(); String recvInterface = edge.getInt2(); IpSpace recvReplies = arpReplies.get(recvNode).get(recvInterface); return AclIpSpace.rejecting(dstIpMatchesSomeRoutePrefix.complement()) .thenPermitting(recvReplies) .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<Edge, IpSpace>>> computeArpTrueEdgeDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<Edge, Set<AbstractRoute>>>> routesWithDestIpEdge, Map<String, Map<String, IpSpace>> arpReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpTrueEdgeDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithDestIpEdge, Entry::getKey, nodeEntry -> toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> toImmutableMap( vrfEntry.getValue(), Entry::getKey, edgeEntry -> { Edge edge = edgeEntry.getKey(); Set<AbstractRoute> routes = edgeEntry.getValue(); String hostname = edge.getNode1(); String vrf = vrfEntry.getKey(); IpSpace dstIpMatchesSomeRoutePrefix = computeRouteMatchConditions( routes, matchingIps.get(hostname).get(vrf)); String recvNode = edge.getNode2(); String recvInterface = edge.getInt2(); IpSpace recvReplies = arpReplies.get(recvNode).get(recvInterface); return AclIpSpace.rejecting(dstIpMatchesSomeRoutePrefix.complement()) .thenPermitting(recvReplies) .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<Edge, IpSpace>>> computeArpTrueEdgeDestIp( Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps, Map<String, Map<String, Map<Edge, Set<AbstractRoute>>>> routesWithDestIpEdge, Map<String, Map<String, IpSpace>> arpReplies) { Span span = GlobalTracer.get().buildSpan("ForwardingAnalysisImpl.computeArpTrueEdgeDestIp").start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; return toImmutableMap( routesWithDestIpEdge, Entry::getKey, nodeEntry -> toImmutableMap( nodeEntry.getValue(), Entry::getKey, vrfEntry -> toImmutableMap( vrfEntry.getValue(), Entry::getKey, edgeEntry -> { Edge edge = edgeEntry.getKey(); Set<AbstractRoute> routes = edgeEntry.getValue(); String hostname = edge.getNode1(); String vrf = vrfEntry.getKey(); IpSpace dstIpMatchesSomeRoutePrefix = computeRouteMatchConditions( routes, matchingIps.get(hostname).get(vrf)); String recvNode = edge.getNode2(); String recvInterface = edge.getInt2(); IpSpace recvReplies = arpReplies.get(recvNode).get(recvInterface); return AclIpSpace.rejecting(dstIpMatchesSomeRoutePrefix.complement()) .thenPermitting(recvReplies) .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();  }