Search in sources :

Example 41 with Configuration

use of org.batfish.datamodel.Configuration in project batfish by batfish.

the class DestinationClasses method buildPrefixTrie.

private void buildPrefixTrie(Map<String, List<Protocol>> protoMap, List<Prefix> dstIps, List<Prefix> notDstIps, PrefixTrieMap pt) {
    // Populate prefix trie
    for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        for (Protocol proto : protoMap.get(router)) {
            Set<Prefix> destinations = new HashSet<>();
            if (!proto.isStatic()) {
                destinations = Graph.getOriginatedNetworks(conf, proto);
            }
            // Add all destinations to the prefix trie relevant to this slice
            for (Prefix p : destinations) {
                if (PrefixUtils.overlap(p, dstIps) && !PrefixUtils.overlap(p, notDstIps)) {
                    Set<Prefix> toAdd = new HashSet<>();
                    for (Prefix pfx : dstIps) {
                        if (p.equals(pfx)) {
                            toAdd.add(p);
                        } else if (pfx.containsPrefix(p)) {
                            toAdd.add(p);
                        } else if (p.containsPrefix(pfx)) {
                            toAdd.add(pfx);
                        }
                    }
                    for (Prefix prefix : toAdd) {
                        pt.add(prefix, router);
                    }
                }
            }
        }
    }
}
Also used : Configuration(org.batfish.datamodel.Configuration) Prefix(org.batfish.datamodel.Prefix) Protocol(org.batfish.symbolic.Protocol) HashSet(java.util.HashSet)

Example 42 with Configuration

use of org.batfish.datamodel.Configuration in project batfish by batfish.

the class MrvConfiguration method toVendorIndependentConfiguration.

@Override
public Configuration toVendorIndependentConfiguration() throws VendorConversionException {
    _c = new Configuration(_hostname, _vendor);
    _c.setDefaultCrossZoneAction(LineAction.ACCEPT);
    _c.setDefaultInboundAction(LineAction.ACCEPT);
    return _c;
}
Also used : VendorConfiguration(org.batfish.vendor.VendorConfiguration) Configuration(org.batfish.datamodel.Configuration)

Example 43 with Configuration

use of org.batfish.datamodel.Configuration in project batfish by batfish.

the class EncoderSlice method initOriginatedPrefixes.

private void initOriginatedPrefixes() {
    for (Entry<String, Configuration> entry : getGraph().getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        for (Protocol proto : _optimizations.getProtocols().get(router)) {
            Set<Prefix> prefixes = Graph.getOriginatedNetworks(conf, proto);
            _originatedNetworks.put(router, proto, prefixes);
        }
    }
}
Also used : Configuration(org.batfish.datamodel.Configuration) Prefix(org.batfish.datamodel.Prefix) IpProtocol(org.batfish.datamodel.IpProtocol) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Protocol(org.batfish.symbolic.Protocol) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol)

Example 44 with Configuration

use of org.batfish.datamodel.Configuration in project batfish by batfish.

the class EncoderSlice method addBestPerProtocolConstraints.

/*
   * Constrains each protocol-best record similarly to the overall
   * best record. It will be better than all choices and equal to
   * at least one of them.
   */
private void addBestPerProtocolConstraints() {
    for (Entry<String, Configuration> entry : getGraph().getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        for (Protocol proto : getProtocols().get(router)) {
            SymbolicRoute bestVars = _symbolicDecisions.getBestVars(_optimizations, router, proto);
            assert (bestVars != null);
            BoolExpr acc = null;
            BoolExpr somePermitted = null;
            for (LogicalEdge e : collectAllImportLogicalEdges(router, conf, proto)) {
                SymbolicRoute vars = correctVars(e);
                if (somePermitted == null) {
                    somePermitted = vars.getPermitted();
                } else {
                    somePermitted = mkOr(somePermitted, vars.getPermitted());
                }
                BoolExpr v = mkAnd(vars.getPermitted(), equal(conf, proto, bestVars, vars, e, true));
                if (acc == null) {
                    acc = v;
                } else {
                    acc = mkOr(acc, v);
                }
                add(mkImplies(vars.getPermitted(), greaterOrEqual(conf, proto, bestVars, vars, e)));
            }
            if (acc != null) {
                add(mkEq(somePermitted, bestVars.getPermitted()));
                add(mkImplies(somePermitted, acc));
            }
        }
    }
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) Configuration(org.batfish.datamodel.Configuration) IpProtocol(org.batfish.datamodel.IpProtocol) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Protocol(org.batfish.symbolic.Protocol) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol)

Example 45 with Configuration

use of org.batfish.datamodel.Configuration in project batfish by batfish.

the class EncoderSlice method addBestOverallConstraints.

/*
   * Constraints that specify that the best choice is
   * better than all alternatives, and is at least one of the choices:
   *
   * (1) if no options are valid, then best is not valid
   * (2) if some option is valid, then we have the following:
   *
   * (best <= best_prot1) and ... and (best <= best_protn)
   * (best =  best_prot1) or  ... or  (best =  best_protn)
   */
private void addBestOverallConstraints() {
    for (Entry<String, Configuration> entry : getGraph().getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        // These constraints will be added at the protocol-level when a single protocol
        if (!_optimizations.getSliceHasSingleProtocol().contains(router)) {
            boolean someProto = false;
            BoolExpr acc = null;
            BoolExpr somePermitted = null;
            SymbolicRoute best = _symbolicDecisions.getBestNeighbor().get(router);
            for (Protocol proto : getProtocols().get(router)) {
                someProto = true;
                SymbolicRoute bestVars = _symbolicDecisions.getBestVars(_optimizations, router, proto);
                assert (bestVars != null);
                if (somePermitted == null) {
                    somePermitted = bestVars.getPermitted();
                } else {
                    somePermitted = mkOr(somePermitted, bestVars.getPermitted());
                }
                BoolExpr val = mkAnd(bestVars.getPermitted(), equal(conf, proto, best, bestVars, null, true));
                if (acc == null) {
                    acc = val;
                } else {
                    acc = mkOr(acc, val);
                }
                add(mkImplies(bestVars.getPermitted(), greaterOrEqual(conf, proto, best, bestVars, null)));
            }
            if (someProto) {
                if (acc != null) {
                    add(mkEq(somePermitted, best.getPermitted()));
                    add(mkImplies(somePermitted, acc));
                }
            } else {
                add(mkNot(best.getPermitted()));
            }
        }
    }
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) Configuration(org.batfish.datamodel.Configuration) IpProtocol(org.batfish.datamodel.IpProtocol) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Protocol(org.batfish.symbolic.Protocol) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol)

Aggregations

Configuration (org.batfish.datamodel.Configuration)170 Test (org.junit.Test)69 Interface (org.batfish.datamodel.Interface)55 Ip (org.batfish.datamodel.Ip)49 Vrf (org.batfish.datamodel.Vrf)45 HashMap (java.util.HashMap)44 Topology (org.batfish.datamodel.Topology)38 VendorConfiguration (org.batfish.vendor.VendorConfiguration)35 Prefix (org.batfish.datamodel.Prefix)33 Edge (org.batfish.datamodel.Edge)32 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)30 Map (java.util.Map)29 Set (java.util.Set)29 TreeMap (java.util.TreeMap)29 BatfishException (org.batfish.common.BatfishException)28 IpAccessList (org.batfish.datamodel.IpAccessList)26 ArrayList (java.util.ArrayList)25 HashSet (java.util.HashSet)25 List (java.util.List)25 SortedSet (java.util.SortedSet)24