Search in sources :

Example 36 with IpAccessList

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()));
    });
}
Also used : Entry(java.util.Map.Entry) Configuration(org.batfish.datamodel.Configuration) AclPermit(org.batfish.z3.state.AclPermit) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) IpAccessList(org.batfish.datamodel.IpAccessList) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 37 with IpAccessList

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));
        }));
    }
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) CommonUtil.toImmutableMap(org.batfish.common.util.CommonUtil.toImmutableMap) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) Function(java.util.function.Function) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Topology(org.batfish.datamodel.Topology) Map(java.util.Map) EmptyIpSpace(org.batfish.datamodel.EmptyIpSpace) Configuration(org.batfish.datamodel.Configuration) LineAction(org.batfish.datamodel.LineAction) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Pair(org.batfish.common.Pair) Nullable(javax.annotation.Nullable) BooleanExpr(org.batfish.z3.expr.BooleanExpr) ImmutableSet(com.google.common.collect.ImmutableSet) NetworkFactory(org.batfish.datamodel.NetworkFactory) ImmutableMap(com.google.common.collect.ImmutableMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) CommonUtil.computeIpOwners(org.batfish.common.util.CommonUtil.computeIpOwners) Range(com.google.common.collect.Range) Set(java.util.Set) IpSpace(org.batfish.datamodel.IpSpace) AclPermit(org.batfish.z3.state.AclPermit) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) List(java.util.List) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) Entry(java.util.Map.Entry) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Type(org.batfish.z3.state.StateParameter.Type) Ip(org.batfish.datamodel.Ip) Entry(java.util.Map.Entry) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Configuration(org.batfish.datamodel.Configuration) IpAccessList(org.batfish.datamodel.IpAccessList) Interface(org.batfish.datamodel.Interface) Pair(org.batfish.common.Pair)

Aggregations

IpAccessList (org.batfish.datamodel.IpAccessList)37 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)19 Configuration (org.batfish.datamodel.Configuration)17 Ip (org.batfish.datamodel.Ip)16 Interface (org.batfish.datamodel.Interface)14 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 BatfishException (org.batfish.common.BatfishException)9 List (java.util.List)7 IpWildcard (org.batfish.datamodel.IpWildcard)7 LineAction (org.batfish.datamodel.LineAction)7 SubRange (org.batfish.datamodel.SubRange)7 ImmutableList (com.google.common.collect.ImmutableList)6 Set (java.util.Set)6 TreeSet (java.util.TreeSet)6 Edge (org.batfish.datamodel.Edge)6 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)6 Prefix (org.batfish.datamodel.Prefix)6 SourceNat (org.batfish.datamodel.SourceNat)6 Map (java.util.Map)5