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);
}
}
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;
}
Aggregations