Search in sources :

Example 1 with PrefixTrie

use of org.batfish.datamodel.PrefixTrie 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 2 with PrefixTrie

use of org.batfish.datamodel.PrefixTrie 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)

Aggregations

Prefix (org.batfish.datamodel.Prefix)2 PrefixTrie (org.batfish.datamodel.PrefixTrie)2 GraphEdge (org.batfish.symbolic.GraphEdge)2 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1