Search in sources :

Example 6 with NodeRoleSpecifier

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

the class InferRoles method call.

@Override
public NodeRoleSpecifier call() {
    NodeRoleSpecifier emptySpecifier = new NodeRoleSpecifier(true);
    int allNodesCount = _nodes.size();
    if (allNodesCount == 0) {
        return emptySpecifier;
    }
    boolean commonRegexFound = inferCommonRegex(_nodes);
    if (!commonRegexFound) {
        return emptySpecifier;
    }
    // find the possible candidates that have a single role group
    List<List<String>> candidateRegexes = possibleRoleGroups();
    if (candidateRegexes.size() == 0) {
        return emptySpecifier;
    }
    // record the set of role "dimensions" for each node, which is a part of its name
    // that may indicate a useful grouping of nodes
    // (e.g., the node's function, location, device type, etc.)
    createRoleDimensions(candidateRegexes);
    Pair<Integer, Double> bestRegexAndScore = findBestRegex(candidateRegexes);
    // select the regex of maximum score, if that score is above threshold
    Optional<NodeRoleSpecifier> optResult = toRoleSpecifierIfAboveThreshold(bestRegexAndScore, candidateRegexes);
    if (optResult.isPresent()) {
        return optResult.get();
    }
    // otherwise we attempt to make the best role found so far more specific
    // NOTE: we could try to refine all possible roles we've considered, rather than
    // greedily only refining the best one, if the greedy approach fails often.
    // try adding a second group around any alphanumeric sequence in the regex;
    // now the role is a concatenation of the strings of both groups
    // NOTE: We could also consider just using the leading alphabetic portion of an alphanumeric
    // sequence as the second group, which would result in less specific groups and could
    // be appropriate for some naming schemes.
    candidateRegexes = possibleSecondRoleGroups(candidateRegexes.get(bestRegexAndScore.getFirst()));
    if (candidateRegexes.size() == 0) {
        return emptySpecifier;
    } else {
        // return the best one according to our metric, even if it's below threshold
        return toRoleSpecifier(findBestRegex(candidateRegexes), candidateRegexes);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier)

Example 7 with NodeRoleSpecifier

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

the class InferRoles method regexToRoleSpecifier.

NodeRoleSpecifier regexToRoleSpecifier(String regex) {
    List<String> regexes = new ArrayList<>();
    regexes.add(regex);
    NodeRoleSpecifier result = new NodeRoleSpecifier(true);
    result.setRoleRegexes(regexes);
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier)

Aggregations

NodeRoleSpecifier (org.batfish.datamodel.NodeRoleSpecifier)7 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 SortedMap (java.util.SortedMap)2 SortedSet (java.util.SortedSet)2 TreeMap (java.util.TreeMap)2 ImmutableConfiguration (org.apache.commons.configuration2.ImmutableConfiguration)2 Configuration (org.batfish.datamodel.Configuration)2 AwsConfiguration (org.batfish.representation.aws.AwsConfiguration)2 HostConfiguration (org.batfish.representation.host.HostConfiguration)2 IptablesVendorConfiguration (org.batfish.representation.iptables.IptablesVendorConfiguration)2 VendorConfiguration (org.batfish.vendor.VendorConfiguration)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1