Search in sources :

Example 16 with NodeInterfacePair

use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.

the class Batfish method getInterfaceBlacklist.

@Nonnull
private SortedSet<NodeInterfacePair> getInterfaceBlacklist() {
    SortedSet<NodeInterfacePair> blacklistInterfaces = Collections.emptySortedSet();
    Path interfaceBlacklistPath = _testrigSettings.getEnvironmentSettings().getInterfaceBlacklistPath();
    if (interfaceBlacklistPath != null && Files.exists(interfaceBlacklistPath)) {
        blacklistInterfaces = parseInterfaceBlacklist(interfaceBlacklistPath);
    }
    return blacklistInterfaces;
}
Also used : Path(java.nio.file.Path) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Nonnull(javax.annotation.Nonnull)

Example 17 with NodeInterfacePair

use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.

the class Batfish method parseInterfaceBlacklist.

private SortedSet<NodeInterfacePair> parseInterfaceBlacklist(Path interfaceBlacklistPath) {
    String interfaceBlacklistText = CommonUtil.readFile(interfaceBlacklistPath);
    SortedSet<NodeInterfacePair> ifaces;
    try {
        ifaces = BatfishObjectMapper.mapper().readValue(interfaceBlacklistText, new TypeReference<SortedSet<NodeInterfacePair>>() {
        });
    } catch (IOException e) {
        throw new BatfishException("Failed to parse interface blacklist", e);
    }
    return ifaces;
}
Also used : CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException)

Example 18 with NodeInterfacePair

use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.

the class Batfish method initRemoteRipNeighbors.

@Override
public void initRemoteRipNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
    for (Entry<String, Configuration> e : configurations.entrySet()) {
        String hostname = e.getKey();
        Configuration c = e.getValue();
        for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
            Vrf vrf = e2.getValue();
            RipProcess proc = vrf.getRipProcess();
            if (proc != null) {
                proc.setRipNeighbors(new TreeMap<>());
                String vrfName = e2.getKey();
                for (String ifaceName : proc.getInterfaces()) {
                    Interface iface = vrf.getInterfaces().get("ifaceName");
                    SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
                    boolean hasNeighbor = false;
                    Ip localIp = iface.getAddress().getIp();
                    if (ifaceEdges != null) {
                        for (Edge edge : ifaceEdges) {
                            if (edge.getNode1().equals(hostname)) {
                                String remoteHostname = edge.getNode2();
                                String remoteIfaceName = edge.getInt2();
                                Configuration remoteNode = configurations.get(remoteHostname);
                                Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
                                Vrf remoteVrf = remoteIface.getVrf();
                                String remoteVrfName = remoteVrf.getName();
                                RipProcess remoteProc = remoteVrf.getRipProcess();
                                if (remoteProc != null) {
                                    if (remoteProc.getRipNeighbors() == null) {
                                        remoteProc.setRipNeighbors(new TreeMap<>());
                                    }
                                    if (remoteProc.getInterfaces().contains(remoteIfaceName)) {
                                        Ip remoteIp = remoteIface.getAddress().getIp();
                                        Pair<Ip, Ip> localKey = new Pair<>(localIp, remoteIp);
                                        RipNeighbor neighbor = proc.getRipNeighbors().get(localKey);
                                        if (neighbor == null) {
                                            hasNeighbor = true;
                                            // initialize local neighbor
                                            neighbor = new RipNeighbor(localKey);
                                            neighbor.setVrf(vrfName);
                                            neighbor.setOwner(c);
                                            neighbor.setInterface(iface);
                                            proc.getRipNeighbors().put(localKey, neighbor);
                                            // initialize remote neighbor
                                            Pair<Ip, Ip> remoteKey = new Pair<>(remoteIp, localIp);
                                            RipNeighbor remoteNeighbor = new RipNeighbor(remoteKey);
                                            remoteNeighbor.setVrf(remoteVrfName);
                                            remoteNeighbor.setOwner(remoteNode);
                                            remoteNeighbor.setInterface(remoteIface);
                                            remoteProc.getRipNeighbors().put(remoteKey, remoteNeighbor);
                                            // link neighbors
                                            neighbor.setRemoteRipNeighbor(remoteNeighbor);
                                            remoteNeighbor.setRemoteRipNeighbor(neighbor);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!hasNeighbor) {
                        Pair<Ip, Ip> key = new Pair<>(localIp, Ip.ZERO);
                        RipNeighbor neighbor = new RipNeighbor(key);
                        neighbor.setVrf(vrfName);
                        neighbor.setOwner(c);
                        neighbor.setInterface(iface);
                        proc.getRipNeighbors().put(key, neighbor);
                    }
                }
            }
        }
    }
}
Also used : RipNeighbor(org.batfish.datamodel.RipNeighbor) HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Ip(org.batfish.datamodel.Ip) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) Vrf(org.batfish.datamodel.Vrf) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf) RipProcess(org.batfish.datamodel.RipProcess) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface) Pair(org.batfish.common.Pair) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair)

Example 19 with NodeInterfacePair

use of org.batfish.datamodel.collections.NodeInterfacePair in project batfish by batfish.

the class CommonUtil method initRemoteOspfNeighbors.

public static void initRemoteOspfNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
    for (Entry<String, Configuration> e : configurations.entrySet()) {
        String hostname = e.getKey();
        Configuration c = e.getValue();
        for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
            Vrf vrf = e2.getValue();
            OspfProcess proc = vrf.getOspfProcess();
            if (proc != null) {
                proc.setOspfNeighbors(new TreeMap<>());
                String vrfName = e2.getKey();
                for (Entry<Long, OspfArea> e3 : proc.getAreas().entrySet()) {
                    long areaNum = e3.getKey();
                    OspfArea area = e3.getValue();
                    for (String ifaceName : area.getInterfaces()) {
                        Interface iface = c.getInterfaces().get(ifaceName);
                        if (iface.getOspfPassive()) {
                            continue;
                        }
                        SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
                        boolean hasNeighbor = false;
                        Ip localIp = iface.getAddress().getIp();
                        if (ifaceEdges != null) {
                            for (Edge edge : ifaceEdges) {
                                if (edge.getNode1().equals(hostname)) {
                                    String remoteHostname = edge.getNode2();
                                    String remoteIfaceName = edge.getInt2();
                                    Configuration remoteNode = configurations.get(remoteHostname);
                                    Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
                                    if (remoteIface.getOspfPassive()) {
                                        continue;
                                    }
                                    Vrf remoteVrf = remoteIface.getVrf();
                                    String remoteVrfName = remoteVrf.getName();
                                    OspfProcess remoteProc = remoteVrf.getOspfProcess();
                                    if (remoteProc != null) {
                                        if (remoteProc.getOspfNeighbors() == null) {
                                            remoteProc.setOspfNeighbors(new TreeMap<>());
                                        }
                                        OspfArea remoteArea = remoteProc.getAreas().get(areaNum);
                                        if (remoteArea != null && remoteArea.getInterfaces().contains(remoteIfaceName)) {
                                            Ip remoteIp = remoteIface.getAddress().getIp();
                                            IpLink localKey = new IpLink(localIp, remoteIp);
                                            OspfNeighbor neighbor = proc.getOspfNeighbors().get(localKey);
                                            if (neighbor == null) {
                                                hasNeighbor = true;
                                                // initialize local neighbor
                                                neighbor = new OspfNeighbor(localKey);
                                                neighbor.setArea(areaNum);
                                                neighbor.setVrf(vrfName);
                                                neighbor.setOwner(c);
                                                neighbor.setInterface(iface);
                                                proc.getOspfNeighbors().put(localKey, neighbor);
                                                // initialize remote neighbor
                                                IpLink remoteKey = new IpLink(remoteIp, localIp);
                                                OspfNeighbor remoteNeighbor = new OspfNeighbor(remoteKey);
                                                remoteNeighbor.setArea(areaNum);
                                                remoteNeighbor.setVrf(remoteVrfName);
                                                remoteNeighbor.setOwner(remoteNode);
                                                remoteNeighbor.setInterface(remoteIface);
                                                remoteProc.getOspfNeighbors().put(remoteKey, remoteNeighbor);
                                                // link neighbors
                                                neighbor.setRemoteOspfNeighbor(remoteNeighbor);
                                                remoteNeighbor.setRemoteOspfNeighbor(neighbor);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (!hasNeighbor) {
                            IpLink key = new IpLink(localIp, Ip.ZERO);
                            OspfNeighbor neighbor = new OspfNeighbor(key);
                            neighbor.setArea(areaNum);
                            neighbor.setVrf(vrfName);
                            neighbor.setOwner(c);
                            neighbor.setInterface(iface);
                            proc.getOspfNeighbors().put(key, neighbor);
                        }
                    }
                }
            }
        }
    }
}
Also used : IpLink(org.batfish.datamodel.IpLink) OspfNeighbor(org.batfish.datamodel.OspfNeighbor) OspfArea(org.batfish.datamodel.OspfArea) Configuration(org.batfish.datamodel.Configuration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Ip(org.batfish.datamodel.Ip) OspfProcess(org.batfish.datamodel.OspfProcess) Vrf(org.batfish.datamodel.Vrf) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Aggregations

NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)19 Edge (org.batfish.datamodel.Edge)13 Configuration (org.batfish.datamodel.Configuration)8 HashMap (java.util.HashMap)7 Set (java.util.Set)7 Interface (org.batfish.datamodel.Interface)7 ImmutableMap (com.google.common.collect.ImmutableMap)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 SortedMap (java.util.SortedMap)5 BatfishException (org.batfish.common.BatfishException)5 FlowTrace (org.batfish.datamodel.FlowTrace)5 Ip (org.batfish.datamodel.Ip)5 Topology (org.batfish.datamodel.Topology)5 ImmutableList (com.google.common.collect.ImmutableList)4 Sets (com.google.common.collect.Sets)4 Path (java.nio.file.Path)4 Entry (java.util.Map.Entry)4 SortedSet (java.util.SortedSet)4