@Test public void testComputeIpsRoutedOutInterfacesMap() { String iface1 = "iface1"; String iface2 = "iface2"; Prefix prefix1 = Prefix.parse("1.2.3.0/24"); Prefix prefix2 = Prefix.parse("2.2.3.0/24"); ConnectedRoute route1 = new ConnectedRoute(prefix1, iface1); ConnectedRoute route2 = new ConnectedRoute(prefix2, iface2); BDD prefix1Bdd = DST.toBDD(prefix1); BDD prefix2Bdd = DST.toBDD(prefix2); { Fib fib = MockFib.builder().build(); assertEquals( ImmutableMap.of(), IpsRoutedOutInterfacesFactory.computeIpsRoutedOutInterfacesMap(fib)); } { Fib fib = MockFib.builder() .setFibEntries( ImmutableMap.of( Ip.ZERO, ImmutableSet.of( new FibEntry(new FibForward(Ip.ZERO, iface1), ImmutableList.of(route1))))) .build(); Map<String, IpSpace> map = IpsRoutedOutInterfacesFactory.computeIpsRoutedOutInterfacesMap(fib); assertThat(map, equalTo(ImmutableMap.of(iface1, EmptyIpSpace.INSTANCE))); } { Fib fib = MockFib.builder() .setFibEntries( ImmutableMap.of( Ip.ZERO, ImmutableSet.of( new FibEntry(new FibForward(Ip.ZERO, iface1), ImmutableList.of(route1))))) .setMatchingIps(ImmutableMap.of(prefix1, prefix1.toIpSpace())) .build(); Map<String, IpSpace> map = IpsRoutedOutInterfacesFactory.computeIpsRoutedOutInterfacesMap(fib); assertEquals(1, map.size()); assertEquals(prefix1Bdd, DST.visit(map.get(iface1))); } { Fib fib = MockFib.builder() .setFibEntries( ImmutableMap.of( Ip.ZERO, ImmutableSet.of( new FibEntry(new FibForward(Ip.ZERO, iface1), ImmutableList.of(route1)), new FibEntry(new FibForward(Ip.ZERO, iface2), ImmutableList.of(route2))))) .setMatchingIps( ImmutableMap.of(prefix1, prefix1.toIpSpace(), prefix2, prefix2.toIpSpace())) .build(); Map<String, IpSpace> map = IpsRoutedOutInterfacesFactory.computeIpsRoutedOutInterfacesMap(fib); assertEquals(2, map.size()); assertEquals(prefix1Bdd, DST.visit(map.get(iface1))); assertEquals(prefix2Bdd, DST.visit(map.get(iface2))); } }
@VisibleForTesting static Map<String, IpSpace> computeIpsRoutedOutInterfacesMap(Fib fib) { Map<Prefix, IpSpace> matchingIps = fib.getMatchingIps(); return fib.allEntries().stream() .collect( groupingBy( fibEntry -> fibEntry.getResolvedToRoute().getNextHopInterface(), mapping( fibEntry -> matchingIps.get(fibEntry.getTopLevelRoute().getNetwork()), collectingAndThen( Collectors.toList(), ipSpaces -> firstNonNull(AclIpSpace.union(ipSpaces), EmptyIpSpace.INSTANCE))))); }
IpsRoutedOutInterfacesFactory { @VisibleForTesting static Map<String, IpSpace> computeIpsRoutedOutInterfacesMap(Fib fib) { Map<Prefix, IpSpace> matchingIps = fib.getMatchingIps(); return fib.allEntries().stream() .collect( groupingBy( fibEntry -> fibEntry.getResolvedToRoute().getNextHopInterface(), mapping( fibEntry -> matchingIps.get(fibEntry.getTopLevelRoute().getNetwork()), collectingAndThen( Collectors.toList(), ipSpaces -> firstNonNull(AclIpSpace.union(ipSpaces), EmptyIpSpace.INSTANCE))))); } }
IpsRoutedOutInterfacesFactory { @VisibleForTesting static Map<String, IpSpace> computeIpsRoutedOutInterfacesMap(Fib fib) { Map<Prefix, IpSpace> matchingIps = fib.getMatchingIps(); return fib.allEntries().stream() .collect( groupingBy( fibEntry -> fibEntry.getResolvedToRoute().getNextHopInterface(), mapping( fibEntry -> matchingIps.get(fibEntry.getTopLevelRoute().getNetwork()), collectingAndThen( Collectors.toList(), ipSpaces -> firstNonNull(AclIpSpace.union(ipSpaces), EmptyIpSpace.INSTANCE))))); } IpsRoutedOutInterfacesFactory(Map<String, Map<String, Fib>> fibs); }
IpsRoutedOutInterfacesFactory { @VisibleForTesting static Map<String, IpSpace> computeIpsRoutedOutInterfacesMap(Fib fib) { Map<Prefix, IpSpace> matchingIps = fib.getMatchingIps(); return fib.allEntries().stream() .collect( groupingBy( fibEntry -> fibEntry.getResolvedToRoute().getNextHopInterface(), mapping( fibEntry -> matchingIps.get(fibEntry.getTopLevelRoute().getNetwork()), collectingAndThen( Collectors.toList(), ipSpaces -> firstNonNull(AclIpSpace.union(ipSpaces), EmptyIpSpace.INSTANCE))))); } IpsRoutedOutInterfacesFactory(Map<String, Map<String, Fib>> fibs);  }
IpsRoutedOutInterfacesFactory { @VisibleForTesting static Map<String, IpSpace> computeIpsRoutedOutInterfacesMap(Fib fib) { Map<Prefix, IpSpace> matchingIps = fib.getMatchingIps(); return fib.allEntries().stream() .collect( groupingBy( fibEntry -> fibEntry.getResolvedToRoute().getNextHopInterface(), mapping( fibEntry -> matchingIps.get(fibEntry.getTopLevelRoute().getNetwork()), collectingAndThen( Collectors.toList(), ipSpaces -> firstNonNull(AclIpSpace.union(ipSpaces), EmptyIpSpace.INSTANCE))))); } IpsRoutedOutInterfacesFactory(Map<String, Map<String, Fib>> fibs);   }