Search in sources :

Example 41 with GraphEdge

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

the class AbstractionBuilder method specialize.

/*
   * Specialize the collection of BDDs representing ACL and route map policies on
   * each edge. Must be synchronized since BDDs are not thread-safe.
   */
private synchronized void specialize(boolean specializeBdds) {
    for (Entry<GraphEdge, InterfacePolicy> entry : _network.getExportPolicyMap().entrySet()) {
        GraphEdge ge = entry.getKey();
        InterfacePolicy pol = entry.getValue();
        InterfacePolicy newPol = pol.restrictStatic(_prefixes);
        newPol = (specializeBdds ? newPol.restrict(_prefixes) : newPol);
        _exportPol.put(ge, newPol);
    }
    for (Entry<GraphEdge, InterfacePolicy> entry : _network.getImportPolicyMap().entrySet()) {
        GraphEdge ge = entry.getKey();
        InterfacePolicy pol = entry.getValue();
        InterfacePolicy newPol = pol.restrictStatic(_prefixes);
        newPol = (specializeBdds ? newPol.restrict(_prefixes) : newPol);
        _importPol.put(ge, newPol);
    }
}
Also used : GraphEdge(org.batfish.symbolic.GraphEdge)

Example 42 with GraphEdge

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

the class BatfishCompressor method processSlice.

/**
 * A slice is an abstracted network for a single destination EC. Given one destination EC, return
 * a mapping from each edge to a filter that will restrict traffic to that EC. We need separate
 * one for each one because they get mutated when we install the filters in the network.
 */
private Map<GraphEdge, EquivalenceClassFilter> processSlice(NetworkSlice slice) {
    Map<GraphEdge, EquivalenceClassFilter> filters = new HashMap<>();
    // get the set of prefixes for this equivalence class.
    TreeSet<Prefix> prefixSet = slice.getHeaderSpace().getDstIps().stream().map(IpWildcard::toPrefix).collect(Collectors.toCollection(TreeSet::new));
    for (GraphEdge edge : slice.getGraph().getAllEdges()) {
        if (!edge.isAbstract() && !_graph.isLoopback(edge)) {
            // add a filter to restrict traffic to this equivalence class.
            filters.put(edge, new EquivalenceClassFilter(new PrefixTrie(prefixSet), slice.getIsDefaultCase()));
        }
    }
    return filters;
}
Also used : PrefixTrie(org.batfish.datamodel.PrefixTrie) HashMap(java.util.HashMap) Prefix(org.batfish.datamodel.Prefix) GraphEdge(org.batfish.symbolic.GraphEdge)

Example 43 with GraphEdge

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

the class BatfishCompressor method addAll.

/**
 * Merge two maps of filters. When there's collision take the union (to allow traffic matching
 * either filter).
 */
private void addAll(Map<GraphEdge, EquivalenceClassFilter> to, Map<GraphEdge, EquivalenceClassFilter> from) {
    for (Entry<GraphEdge, EquivalenceClassFilter> entry : from.entrySet()) {
        GraphEdge graphEdge = entry.getKey();
        EquivalenceClassFilter filter = entry.getValue();
        if (!to.containsKey(graphEdge)) {
            to.put(graphEdge, filter);
        } else {
            // both maps have filters for this edge -- merge them together.
            TreeSet<Prefix> mergedPrefixes = new TreeSet<>(Sets.union(to.get(graphEdge)._prefixTrie.getPrefixes(), filter._prefixTrie.getPrefixes()));
            EquivalenceClassFilter mergedFilter = new EquivalenceClassFilter(new PrefixTrie(mergedPrefixes), to.get(graphEdge)._isForDefaultSlice || filter._isForDefaultSlice);
            to.put(graphEdge, mergedFilter);
        }
    }
}
Also used : PrefixTrie(org.batfish.datamodel.PrefixTrie) TreeSet(java.util.TreeSet) Prefix(org.batfish.datamodel.Prefix) GraphEdge(org.batfish.symbolic.GraphEdge)

Example 44 with GraphEdge

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

the class BDDNetwork method computeInterfacePolicies.

/*
   * For each interface in the network, creates a canonical
   * representation of the import and export policies on this interface.
   */
private void computeInterfacePolicies() {
    for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        // Skip if doesn't match the node regex
        Matcher m = _nodeSpecifier.getRegex().matcher(router);
        if (!m.matches()) {
            continue;
        }
        Configuration conf = entry.getValue();
        List<GraphEdge> edges = _graph.getEdgeMap().get(router);
        for (GraphEdge ge : edges) {
            // Import BGP policy
            RoutingPolicy importBgp = _graph.findImportRoutingPolicy(router, Protocol.BGP, ge);
            if (importBgp != null) {
                BDDRoute rec = computeBDD(_graph, conf, importBgp, true);
                _importBgpPolicies.put(ge, rec);
            }
            // Export BGP policy
            RoutingPolicy exportBgp = _graph.findExportRoutingPolicy(router, Protocol.BGP, ge);
            if (exportBgp != null) {
                BDDRoute rec = computeBDD(_graph, conf, exportBgp, true);
                _exportBgpPolicies.put(ge, rec);
            }
            IpAccessList in = ge.getStart().getIncomingFilter();
            IpAccessList out = ge.getStart().getOutgoingFilter();
            // Incoming ACL
            if (in != null) {
                BDDAcl x = BDDAcl.create(conf, in, true);
                _inAcls.put(ge, x);
            }
            // Outgoing ACL
            if (out != null) {
                BDDAcl x = BDDAcl.create(conf, out, true);
                _outAcls.put(ge, x);
            }
        }
    }
    for (Entry<String, List<GraphEdge>> entry : _graph.getEdgeMap().entrySet()) {
        String router = entry.getKey();
        // Skip if doesn't match the node regex
        Matcher m = _nodeSpecifier.getRegex().matcher(router);
        if (!m.matches()) {
            continue;
        }
        List<GraphEdge> edges = entry.getValue();
        Configuration conf = _graph.getConfigurations().get(router);
        for (GraphEdge ge : edges) {
            BDDRoute bgpIn = _importBgpPolicies.get(ge);
            BDDRoute bgpOut = _exportBgpPolicies.get(ge);
            BDDAcl aclIn = _inAcls.get(ge);
            BDDAcl aclOut = _outAcls.get(ge);
            Integer ospfCost = ge.getStart().getOspfCost();
            SortedSet<Pair<Prefix, Integer>> staticPrefixes = new TreeSet<>();
            SortedSet<StaticRoute> staticRoutes = conf.getDefaultVrf().getStaticRoutes();
            for (StaticRoute sr : staticRoutes) {
                Prefix pfx = sr.getNetwork();
                Integer adminCost = sr.getAdministrativeCost();
                Pair<Prefix, Integer> tup = new Pair<>(pfx, adminCost);
                staticPrefixes.add(tup);
            }
            InterfacePolicy ipol = new InterfacePolicy(aclIn, bgpIn, null, staticPrefixes);
            InterfacePolicy epol = new InterfacePolicy(aclOut, bgpOut, ospfCost, null);
            _importPolicyMap.put(ge, ipol);
            _exportPolicyMap.put(ge, epol);
        }
    }
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) Matcher(java.util.regex.Matcher) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Prefix(org.batfish.datamodel.Prefix) InterfacePolicy(org.batfish.symbolic.abstraction.InterfacePolicy) TreeSet(java.util.TreeSet) IpAccessList(org.batfish.datamodel.IpAccessList) List(java.util.List) IpAccessList(org.batfish.datamodel.IpAccessList) GraphEdge(org.batfish.symbolic.GraphEdge) Pair(org.batfish.common.Pair)

Example 45 with GraphEdge

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

the class CounterExample method buildFlowTraceHop.

/*
   * Build an individual flow hop along a path
   */
private FlowTraceHop buildFlowTraceHop(GraphEdge ge, String route) {
    String node1 = ge.getRouter();
    String int1 = ge.getStart().getName();
    String node2 = ge.getPeer() == null ? "(none)" : ge.getPeer();
    String int2 = ge.getEnd() == null ? "null_interface" : ge.getEnd().getName();
    Edge edge = new Edge(node1, int1, node2, int2);
    SortedSet<String> routes = new TreeSet<>();
    routes.add(route);
    return new FlowTraceHop(edge, routes, null);
}
Also used : FlowTraceHop(org.batfish.datamodel.FlowTraceHop) TreeSet(java.util.TreeSet) Edge(org.batfish.datamodel.Edge) GraphEdge(org.batfish.symbolic.GraphEdge)

Aggregations

GraphEdge (org.batfish.symbolic.GraphEdge)47 BoolExpr (com.microsoft.z3.BoolExpr)23 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Graph (org.batfish.symbolic.Graph)14 TreeSet (java.util.TreeSet)13 Prefix (org.batfish.datamodel.Prefix)12 ArithExpr (com.microsoft.z3.ArithExpr)10 Configuration (org.batfish.datamodel.Configuration)10 Protocol (org.batfish.symbolic.Protocol)10 HashSet (java.util.HashSet)8 Interface (org.batfish.datamodel.Interface)8 Context (com.microsoft.z3.Context)7 Map (java.util.Map)7 Ip (org.batfish.datamodel.Ip)7 IpAccessList (org.batfish.datamodel.IpAccessList)7 TreeMap (java.util.TreeMap)6 IpProtocol (org.batfish.datamodel.IpProtocol)6 BitVecExpr (com.microsoft.z3.BitVecExpr)5