Search in sources :

Example 1 with Protocol

use of org.batfish.symbolic.Protocol in project batfish by batfish.

the class DestinationClasses method buildProtocolMap.

/*
   * Initialize a mapping from router to collection of protocol
   */
private Map<String, List<Protocol>> buildProtocolMap() {
    // Figure out which protocols are running on which devices
    Map<String, List<Protocol>> protocols = new HashMap<>();
    for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        List<Protocol> protos = new ArrayList<>();
        protocols.put(router, protos);
        if (conf.getDefaultVrf().getOspfProcess() != null) {
            protos.add(Protocol.OSPF);
        }
        if (conf.getDefaultVrf().getBgpProcess() != null) {
            protos.add(Protocol.BGP);
        }
        if (!conf.getDefaultVrf().getStaticRoutes().isEmpty()) {
            protos.add(Protocol.STATIC);
        }
        if (!conf.getInterfaces().isEmpty()) {
            protos.add(Protocol.CONNECTED);
        }
    }
    return protocols;
}
Also used : Configuration(org.batfish.datamodel.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.batfish.symbolic.Protocol)

Example 2 with Protocol

use of org.batfish.symbolic.Protocol 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 3 with Protocol

use of org.batfish.symbolic.Protocol 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 4 with Protocol

use of org.batfish.symbolic.Protocol 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 5 with Protocol

use of org.batfish.symbolic.Protocol in project batfish by batfish.

the class EncoderSlice method addBestVariables.

/*
   * Initialize variables representing the best choice both for
   * each protocol as well as for the router as a whole
   */
private void addBestVariables() {
    for (Entry<String, List<Protocol>> entry : getProtocols().entrySet()) {
        String router = entry.getKey();
        List<Protocol> allProtos = entry.getValue();
        // Overall best
        for (int len = 0; len <= BITS; len++) {
            String name = String.format("%d_%s%s_%s_%s_%s", _encoder.getId(), _sliceName, router, "OVERALL", "BEST", "None");
            String historyName = name + "_history";
            SymbolicEnum<Protocol> h = new SymbolicEnum<>(this, allProtos, historyName);
            SymbolicRoute evBest = new SymbolicRoute(this, name, router, Protocol.BEST, _optimizations, h, false);
            getAllSymbolicRecords().add(evBest);
            _symbolicDecisions.getBestNeighbor().put(router, evBest);
        }
        // Best per protocol
        if (!_optimizations.getSliceHasSingleProtocol().contains(router)) {
            for (Protocol proto : getProtocols().get(router)) {
                String name = String.format("%d_%s%s_%s_%s_%s", _encoder.getId(), _sliceName, router, proto.name(), "BEST", "None");
                for (int len = 0; len <= BITS; len++) {
                    SymbolicRoute evBest = new SymbolicRoute(this, name, router, proto, _optimizations, null, false);
                    getAllSymbolicRecords().add(evBest);
                    _symbolicDecisions.getBestNeighborPerProtocol().put(router, proto, evBest);
                }
            }
        }
    }
}
Also used : IpAccessList(org.batfish.datamodel.IpAccessList) ArrayList(java.util.ArrayList) List(java.util.List) IpProtocol(org.batfish.datamodel.IpProtocol) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Protocol(org.batfish.symbolic.Protocol) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol)

Aggregations

Protocol (org.batfish.symbolic.Protocol)27 IpProtocol (org.batfish.datamodel.IpProtocol)16 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)15 Configuration (org.batfish.datamodel.Configuration)14 MatchProtocol (org.batfish.datamodel.routing_policy.expr.MatchProtocol)14 ArrayList (java.util.ArrayList)12 GraphEdge (org.batfish.symbolic.GraphEdge)11 BoolExpr (com.microsoft.z3.BoolExpr)10 Prefix (org.batfish.datamodel.Prefix)10 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)5 BatfishException (org.batfish.common.BatfishException)5 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)5 Interface (org.batfish.datamodel.Interface)4 IpAccessList (org.batfish.datamodel.IpAccessList)4 Graph (org.batfish.symbolic.Graph)4 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)3 Ip (org.batfish.datamodel.Ip)3