Search in sources :

Example 6 with Tuple

use of org.batfish.symbolic.utils.Tuple in project batfish by batfish.

the class AbstractionBuilder method createAbstractNetwork.

/*
   * Create a collection of abstract configurations given the roles computed
   * and the collection of concrete devices. Chooses a collection of canonical
   * representatives from each role, and then removes all their interfaces etc
   * that connect to non-canonical routers.
   */
private Tuple<Graph, AbstractionMap> createAbstractNetwork() {
    Map<Integer, Set<String>> canonicalChoices = pickCanonicalRouters();
    Set<String> abstractRouters = new HashSet<>();
    for (Set<String> canonical : canonicalChoices.values()) {
        abstractRouters.addAll(canonical);
    }
    // Create the abstract configurations
    Map<String, Configuration> newConfigs = new HashMap<>();
    for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        if (abstractRouters.contains(router)) {
            Configuration abstractConf = createAbstractConfig(abstractRouters, conf);
            newConfigs.put(router, abstractConf);
        }
    }
    Graph abstractGraph = new Graph(_batfish, newConfigs);
    AbstractionMap map = new AbstractionMap(canonicalChoices, _abstractGroups.getParitionMap());
    return new Tuple<>(abstractGraph, map);
}
Also used : SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) Configuration(org.batfish.datamodel.Configuration) HashMap(java.util.HashMap) Graph(org.batfish.symbolic.Graph) Tuple(org.batfish.symbolic.utils.Tuple) HashSet(java.util.HashSet)

Example 7 with Tuple

use of org.batfish.symbolic.utils.Tuple in project batfish by batfish.

the class DestinationClasses method buildHeaderSpaceEcs.

private void buildHeaderSpaceEcs(Map<Set<String>, List<Prefix>> destinationMap) {
    destinationMap.forEach((devices, prefixes) -> {
        HeaderSpace h = createHeaderSpace(prefixes);
        if (_headerspace != null) {
            copyAllButDestinationIp(h, _headerspace);
        }
        _headerspaceMap.put(devices, new Tuple<>(h, new Tuple<>(prefixes, false)));
    });
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) Tuple(org.batfish.symbolic.utils.Tuple)

Example 8 with Tuple

use of org.batfish.symbolic.utils.Tuple in project batfish by batfish.

the class NetworkSlice method allSlices.

public static ArrayList<Supplier<NetworkSlice>> allSlices(DestinationClasses dcs, int fails) {
    BDDNetwork network = BDDNetwork.create(dcs.getGraph());
    ArrayList<Supplier<NetworkSlice>> classes = new ArrayList<>();
    for (Entry<Set<String>, Tuple<HeaderSpace, Tuple<List<Prefix>, Boolean>>> entry : dcs.getHeaderspaceMap().entrySet()) {
        Set<String> devices = entry.getKey();
        HeaderSpace headerspace = entry.getValue().getFirst();
        List<Prefix> prefixes = entry.getValue().getSecond().getFirst();
        Boolean isDefaultCase = entry.getValue().getSecond().getSecond();
        Supplier<NetworkSlice> sup = () -> AbstractionBuilder.createGraph(dcs, network, devices, headerspace, prefixes, fails, isDefaultCase);
        classes.add(sup);
    }
    return classes;
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) BDDNetwork(org.batfish.symbolic.bdd.BDDNetwork) HeaderSpace(org.batfish.datamodel.HeaderSpace) Prefix(org.batfish.datamodel.Prefix) Supplier(java.util.function.Supplier) List(java.util.List) ArrayList(java.util.ArrayList) Tuple(org.batfish.symbolic.utils.Tuple)

Example 9 with Tuple

use of org.batfish.symbolic.utils.Tuple in project batfish by batfish.

the class Roles method computeRoles.

/*
   * Compute all the devices/interfaces configured with the
   * equivalent policies.
   */
private void computeRoles(List<Prefix> prefixes) {
    Map<BDDRoute, SortedSet<String>> importBgpEcs = new HashMap<>();
    Map<BDDRoute, SortedSet<String>> exportBgpEcs = new HashMap<>();
    Map<BDD, SortedSet<String>> incomingAclEcs = new HashMap<>();
    Map<BDD, SortedSet<String>> outgoingAclEcs = new HashMap<>();
    Map<Tuple<InterfacePolicy, InterfacePolicy>, SortedSet<String>> interfaceEcs = new HashMap<>();
    Map<Set<Tuple<InterfacePolicy, InterfacePolicy>>, SortedSet<String>> nodeEcs = new HashMap<>();
    SortedSet<String> importBgpNull = new TreeSet<>();
    SortedSet<String> exportBgpNull = new TreeSet<>();
    SortedSet<String> incomingAclNull = new TreeSet<>();
    SortedSet<String> outgoingAclNull = new TreeSet<>();
    for (Entry<String, List<GraphEdge>> entry : _graph.getEdgeMap().entrySet()) {
        String router = entry.getKey();
        Matcher m = _nodeSpecifier.getRegex().matcher(router);
        if (!m.matches()) {
            continue;
        }
        List<GraphEdge> ges = entry.getValue();
        Set<Tuple<InterfacePolicy, InterfacePolicy>> nodeEc = new HashSet<>();
        for (GraphEdge ge : ges) {
            String s = ge.toString();
            BDDRoute x1 = _network.getImportBgpPolicies().get(ge);
            if (x1 == null) {
                importBgpNull.add(s);
            } else {
                x1 = (prefixes == null ? x1 : x1.restrict(prefixes));
                SortedSet<String> ec = importBgpEcs.computeIfAbsent(x1, k -> new TreeSet<>());
                ec.add(s);
            }
            BDDRoute x2 = _network.getExportBgpPolicies().get(ge);
            if (x2 == null) {
                exportBgpNull.add(s);
            } else {
                x2 = (prefixes == null ? x2 : x2.restrict(prefixes));
                SortedSet<String> ec = exportBgpEcs.computeIfAbsent(x2, k -> new TreeSet<>());
                ec.add(s);
            }
            BDDAcl x4 = _network.getInAcls().get(ge);
            if (x4 == null) {
                incomingAclNull.add(s);
            } else {
                x4 = (prefixes == null ? x4 : x4.restrict(prefixes));
                SortedSet<String> ec = incomingAclEcs.computeIfAbsent(x4.getBdd(), k -> new TreeSet<>());
                ec.add(s);
            }
            BDDAcl x5 = _network.getOutAcls().get(ge);
            if (x5 == null) {
                outgoingAclNull.add(s);
            } else {
                x5 = (prefixes == null ? x5 : x5.restrict(prefixes));
                SortedSet<String> ec = outgoingAclEcs.computeIfAbsent(x5.getBdd(), k -> new TreeSet<>());
                ec.add(s);
            }
            InterfacePolicy x6 = _network.getImportPolicyMap().get(ge);
            InterfacePolicy x7 = _network.getExportPolicyMap().get(ge);
            x6 = (x6 == null || prefixes == null ? x6 : x6.restrict(prefixes));
            x7 = (x7 == null || prefixes == null ? x7 : x7.restrict(prefixes));
            Tuple<InterfacePolicy, InterfacePolicy> tup = new Tuple<>(x6, x7);
            SortedSet<String> ec = interfaceEcs.computeIfAbsent(tup, k -> new TreeSet<>());
            ec.add(s);
            nodeEc.add(tup);
        }
        SortedSet<String> ec = nodeEcs.computeIfAbsent(nodeEc, k -> new TreeSet<>());
        ec.add(router);
    }
    Comparator<SortedSet<String>> c = comparator();
    _bgpInEcs = new ArrayList<>(importBgpEcs.values());
    if (!importBgpNull.isEmpty()) {
        _bgpInEcs.add(importBgpNull);
    }
    _bgpInEcs.sort(c);
    _bgpOutEcs = new ArrayList<>(exportBgpEcs.values());
    if (!exportBgpNull.isEmpty()) {
        _bgpOutEcs.add(exportBgpNull);
    }
    _bgpOutEcs.sort(c);
    _aclInEcs = new ArrayList<>(incomingAclEcs.values());
    if (!incomingAclNull.isEmpty()) {
        _aclInEcs.add(incomingAclNull);
    }
    _aclInEcs.sort(c);
    _aclOutEcs = new ArrayList<>(outgoingAclEcs.values());
    if (!outgoingAclNull.isEmpty()) {
        _aclOutEcs.add(outgoingAclNull);
    }
    _aclOutEcs.sort(c);
    _interfaceEcs = new ArrayList<>(interfaceEcs.values());
    _interfaceEcs.sort(c);
    _nodeEcs = new ArrayList<>(nodeEcs.values());
    _nodeEcs.sort(c);
}
Also used : BDD(net.sf.javabdd.BDD) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) SortedSet(java.util.SortedSet) BDDRoute(org.batfish.symbolic.bdd.BDDRoute) TreeSet(java.util.TreeSet) BDDAcl(org.batfish.symbolic.bdd.BDDAcl) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) GraphEdge(org.batfish.symbolic.GraphEdge) Tuple(org.batfish.symbolic.utils.Tuple)

Aggregations

Tuple (org.batfish.symbolic.utils.Tuple)9 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 HeaderSpace (org.batfish.datamodel.HeaderSpace)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 SortedSet (java.util.SortedSet)3 GraphEdge (org.batfish.symbolic.GraphEdge)3 BoolExpr (com.microsoft.z3.BoolExpr)2 List (java.util.List)2 Supplier (java.util.function.Supplier)2 Prefix (org.batfish.datamodel.Prefix)2 Graph (org.batfish.symbolic.Graph)2 Model (com.microsoft.z3.Model)1 Status (com.microsoft.z3.Status)1 Collection (java.util.Collection)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1