use of org.batfish.datamodel.IpAccessList in project batfish by batfish.
the class SynthesizerInputImpl method computeSourceNats.
private Map<String, Map<String, List<Entry<AclPermit, BooleanExpr>>>> computeSourceNats() {
return toImmutableMap(_topologyInterfaces, Entry::getKey, topologyInterfacesEntryByHostname -> {
String hostname = topologyInterfacesEntryByHostname.getKey();
Set<String> ifaces = topologyInterfacesEntryByHostname.getValue();
Configuration c = _configurations.get(hostname);
return toImmutableMap(ifaces, Function.identity(), ifaceName -> c.getInterfaces().get(ifaceName).getSourceNats().stream().map(sourceNat -> {
IpAccessList acl = sourceNat.getAcl();
String aclName = acl == null ? DEFAULT_SOURCE_NAT_ACL.getName() : acl.getName();
AclPermit preconditionPreTransformationState = new AclPermit(hostname, aclName);
BooleanExpr transformationConstraint = new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(sourceNat.getPoolIpFirst().asLong(), sourceNat.getPoolIpLast().asLong())));
return Maps.immutableEntry(preconditionPreTransformationState, transformationConstraint);
}).collect(ImmutableList.toImmutableList()));
});
}
use of org.batfish.datamodel.IpAccessList in project batfish by batfish.
the class SynthesizerInputImpl method computeEnabledAcls.
private Map<String, Map<String, IpAccessList>> computeEnabledAcls() {
if (_topologyInterfaces != null) {
return toImmutableMap(_topologyInterfaces, Entry::getKey, /* node */
topologyInterfacesEntry -> {
String hostname = topologyInterfacesEntry.getKey();
Configuration c = _configurations.get(hostname);
return topologyInterfacesEntry.getValue().stream().flatMap(ifaceName -> {
Interface i = c.getInterfaces().get(ifaceName);
ImmutableList.Builder<Pair<String, IpAccessList>> interfaceAcls = ImmutableList.builder();
IpAccessList aclIn = i.getIncomingFilter();
IpAccessList aclOut = i.getOutgoingFilter();
if (aclIn != null) {
aclIn = _ipAclListSpecializer.specialize(aclIn);
interfaceAcls.add(new Pair<>(aclIn.getName(), aclIn));
}
if (aclOut != null) {
aclOut = _ipAclListSpecializer.specialize(aclOut);
interfaceAcls.add(new Pair<>(aclOut.getName(), aclOut));
}
i.getSourceNats().forEach(sourceNat -> {
IpAccessList sourceNatAcl = sourceNat.getAcl();
if (sourceNatAcl != null) {
interfaceAcls.add(new Pair<>(sourceNatAcl.getName(), sourceNatAcl));
} else {
interfaceAcls.add(new Pair<>(DEFAULT_SOURCE_NAT_ACL.getName(), DEFAULT_SOURCE_NAT_ACL));
}
});
return interfaceAcls.build().stream();
}).collect(ImmutableSet.toImmutableSet()).stream().collect(ImmutableMap.toImmutableMap(Pair::getFirst, Pair::getSecond));
});
} else {
return _configurations.entrySet().stream().filter(e -> !_disabledNodes.contains(e.getKey())).collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> {
String hostname = e.getKey();
Set<String> disabledAcls = _disabledAcls.get(hostname);
return e.getValue().getIpAccessLists().entrySet().stream().filter(e2 -> disabledAcls == null || !disabledAcls.contains(e2.getKey())).collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
}));
}
}
Aggregations