Search in sources :

Example 1 with VrrpGroup

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;
}
Also used : VrrpGroup(org.batfish.datamodel.VrrpGroup)

Example 2 with VrrpGroup

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;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) VrrpGroup(org.batfish.datamodel.VrrpGroup) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) IdentityHashMap(java.util.IdentityHashMap) TreeSet(java.util.TreeSet) Interface(org.batfish.datamodel.Interface) Pair(org.batfish.common.Pair) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair)

Aggregations

VrrpGroup (org.batfish.datamodel.VrrpGroup)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 Pair (org.batfish.common.Pair)1 Interface (org.batfish.datamodel.Interface)1 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)1 Ip (org.batfish.datamodel.Ip)1 NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)1