use of org.batfish.datamodel.VrrpGroup in project batfish by batfish.
the class ConfigurationBuilder method enterIfia_vrrp_group.
@Override
public void enterIfia_vrrp_group(Ifia_vrrp_groupContext ctx) {
int group = toInt(ctx.number);
VrrpGroup currentVrrpGroup = _currentInterface.getVrrpGroups().get(group);
if (currentVrrpGroup == null) {
currentVrrpGroup = new VrrpGroup(group);
currentVrrpGroup.setPreempt(DEFAULT_VRRP_PREEMPT);
currentVrrpGroup.setPriority(DEFAULT_VRRP_PRIORITY);
_currentInterface.getVrrpGroups().put(group, currentVrrpGroup);
}
_currentVrrpGroup = currentVrrpGroup;
}
use of org.batfish.datamodel.VrrpGroup in project batfish by batfish.
the class CommonUtil method computeIpOwners.
public static Map<Ip, Set<String>> computeIpOwners(boolean excludeInactive, Map<String, Map<String, Interface>> enabledInterfaces) {
// TODO: confirm VRFs are handled correctly
Map<Ip, Set<String>> ipOwners = new HashMap<>();
Map<Pair<InterfaceAddress, Integer>, Set<Interface>> vrrpGroups = new HashMap<>();
enabledInterfaces.forEach((hostname, currentEnabledInterfaces) -> {
for (Interface i : currentEnabledInterfaces.values()) {
if (!i.getActive() && (excludeInactive || !i.getBlacklisted())) {
continue;
}
// collect vrrp info
i.getVrrpGroups().forEach((groupNum, vrrpGroup) -> {
InterfaceAddress address = vrrpGroup.getVirtualAddress();
if (address == null) {
// never win the election, so is not a candidate.
return;
}
Pair<InterfaceAddress, Integer> key = new Pair<>(address, groupNum);
Set<Interface> candidates = vrrpGroups.computeIfAbsent(key, k -> Collections.newSetFromMap(new IdentityHashMap<>()));
candidates.add(i);
});
// collect prefixes
i.getAllAddresses().stream().map(InterfaceAddress::getIp).forEach(ip -> {
Set<String> owners = ipOwners.computeIfAbsent(ip, k -> new HashSet<>());
owners.add(hostname);
});
}
});
vrrpGroups.forEach((p, candidates) -> {
int groupNum = p.getSecond();
InterfaceAddress address = p.getFirst();
Ip ip = address.getIp();
int lowestPriority = Integer.MAX_VALUE;
String bestCandidate = null;
SortedSet<String> bestCandidates = new TreeSet<>();
for (Interface candidate : candidates) {
VrrpGroup group = candidate.getVrrpGroups().get(groupNum);
int currentPriority = group.getPriority();
if (currentPriority < lowestPriority) {
lowestPriority = currentPriority;
bestCandidates.clear();
bestCandidate = candidate.getOwner().getHostname();
}
if (currentPriority == lowestPriority) {
bestCandidates.add(candidate.getOwner().getHostname());
}
}
if (bestCandidates.size() != 1) {
String deterministicBestCandidate = bestCandidates.first();
bestCandidate = deterministicBestCandidate;
// _logger.redflag(
// "Arbitrarily choosing best vrrp candidate: '"
// + deterministicBestCandidate
// + " for prefix/groupNumber: '"
// + p.toString()
// + "' among multiple best candidates: "
// + bestCandidates);
}
Set<String> owners = ipOwners.computeIfAbsent(ip, k -> new HashSet<>());
owners.add(bestCandidate);
});
return ipOwners;
}
Aggregations