use of org.batfish.datamodel.IpWildcardSetIpSpace in project batfish by batfish.
the class CommonUtil method initPrivateIpsByPublicIp.
@VisibleForTesting
static SetMultimap<Ip, IpWildcardSetIpSpace> initPrivateIpsByPublicIp(Map<String, Configuration> configurations) {
/*
* Very hacky mapping from public IP to set of spaces of possible natted private IPs.
* Does not currently support source-nat acl.
*
* The current implementation just considers every IP in every prefix on a non-masquerading
* interface (except the local address in each such prefix) to be a possible private IP
* match for every public IP referred to by every source-nat pool on a masquerading interface.
*/
ImmutableSetMultimap.Builder<Ip, IpWildcardSetIpSpace> builder = ImmutableSetMultimap.builder();
for (Configuration c : configurations.values()) {
Collection<Interface> interfaces = c.getInterfaces().values();
Set<InterfaceAddress> nonNattedInterfaceAddresses = interfaces.stream().filter(i -> i.getSourceNats().isEmpty()).flatMap(i -> i.getAllAddresses().stream()).collect(ImmutableSet.toImmutableSet());
Set<IpWildcard> blacklist = nonNattedInterfaceAddresses.stream().map(address -> new IpWildcard(address.getIp(), Ip.ZERO)).collect(ImmutableSet.toImmutableSet());
Set<IpWildcard> whitelist = nonNattedInterfaceAddresses.stream().map(address -> new IpWildcard(address.getPrefix())).collect(ImmutableSet.toImmutableSet());
IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(whitelist).excluding(blacklist).build();
interfaces.stream().flatMap(i -> i.getSourceNats().stream()).forEach(sourceNat -> {
for (long ipAsLong = sourceNat.getPoolIpFirst().asLong(); ipAsLong <= sourceNat.getPoolIpLast().asLong(); ipAsLong++) {
Ip currentPoolIp = new Ip(ipAsLong);
builder.put(currentPoolIp, ipSpace);
}
});
}
return builder.build();
}
Aggregations