Search in sources :

Example 6 with BgpNeighbor

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

the class Graph method initEbgpNeighbors.

/*
   * Initialize external eBGP neighbors by looking for BGP neighbors
   * where their is no neighbor in the configurations, and the IPs align.
   */
private void initEbgpNeighbors() {
    Map<String, List<Ip>> ips = new HashMap<>();
    Map<String, List<BgpNeighbor>> neighbors = new HashMap<>();
    for (Entry<String, Configuration> entry : _configurations.entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        List<Ip> ipList = new ArrayList<>();
        List<BgpNeighbor> ns = new ArrayList<>();
        ips.put(router, ipList);
        neighbors.put(router, ns);
        if (conf.getDefaultVrf().getBgpProcess() != null) {
            BgpProcess bgp = conf.getDefaultVrf().getBgpProcess();
            for (BgpNeighbor neighbor : bgp.getNeighbors().values()) {
                ipList.add(neighbor.getAddress());
                ns.add(neighbor);
            }
        }
    }
    for (Entry<String, Configuration> entry : _configurations.entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        List<Ip> ipList = ips.get(router);
        List<BgpNeighbor> ns = neighbors.get(router);
        if (conf.getDefaultVrf().getBgpProcess() != null) {
            List<GraphEdge> edges = _edgeMap.get(router);
            for (GraphEdge ge : edges) {
                for (int i = 0; i < ipList.size(); i++) {
                    Ip ip = ipList.get(i);
                    BgpNeighbor n = ns.get(i);
                    Interface iface = ge.getStart();
                    if (ip != null && iface.getAddress().getPrefix().containsIp(ip)) {
                        _ebgpNeighbors.put(ge, n);
                    }
                }
            }
        }
    }
}
Also used : Configuration(org.batfish.datamodel.Configuration) HashMap(java.util.HashMap) BgpProcess(org.batfish.datamodel.BgpProcess) Ip(org.batfish.datamodel.Ip) ArrayList(java.util.ArrayList) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) List(java.util.List) ArrayList(java.util.ArrayList) CommunityList(org.batfish.datamodel.CommunityList) Interface(org.batfish.datamodel.Interface)

Example 7 with BgpNeighbor

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

the class Graph method findRouterId.

/*
   * Find the router Id for the neighbor corresponding to a logical edge.
   */
public long findRouterId(GraphEdge ge, Protocol proto) {
    GraphEdge eOther = _otherEnd.get(ge);
    if (proto.isOspf() || proto.isConnected() || proto.isStatic()) {
        return 0L;
    }
    if (eOther != null) {
        String peer = eOther.getRouter();
        Configuration peerConf = getConfigurations().get(peer);
        return routerId(peerConf, proto);
    }
    BgpNeighbor n = findBgpNeighbor(ge);
    if (n != null && n.getAddress() != null) {
        return n.getAddress().asLong();
    }
    throw new BatfishException("Unable to find router id for " + ge + "," + proto.name());
}
Also used : BgpNeighbor(org.batfish.datamodel.BgpNeighbor) BatfishException(org.batfish.common.BatfishException) Configuration(org.batfish.datamodel.Configuration)

Example 8 with BgpNeighbor

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

the class Graph method isEdgeUsed.

/*
   * Check if a topology edge is used in a particular protocol.
   */
public boolean isEdgeUsed(Configuration conf, Protocol proto, GraphEdge ge) {
    Interface iface = ge.getStart();
    // Use a null routed edge, but only for the static protocol
    if (ge.isNullEdge()) {
        return proto.isStatic();
    }
    // Don't use if interface is not active
    if (!isInterfaceActive(proto, iface)) {
        return false;
    }
    // Exclude abstract iBGP edges from all protocols except BGP
    if (iface.getName().startsWith("iBGP-")) {
        return proto.isBgp();
    }
    // Never use Loopbacks for any protocol except connected
    if (ge.getStart().isLoopback(conf.getConfigurationFormat())) {
        return proto.isConnected();
    }
    // Don't use ospf over edges to hosts / external
    if ((ge.getPeer() == null || isHost(ge.getPeer())) && proto.isOspf()) {
        return false;
    }
    // Only use specified edges from static routes
    if (proto.isStatic()) {
        List<StaticRoute> srs = getStaticRoutes().get(conf.getName(), iface.getName());
        return iface.getActive() && srs != null && srs.size() > 0;
    }
    // Only use an edge in BGP if there is an explicit peering
    if (proto.isBgp()) {
        BgpNeighbor n1 = _ebgpNeighbors.get(ge);
        BgpNeighbor n2 = _ibgpNeighbors.get(ge);
        return n1 != null || n2 != null;
    }
    return true;
}
Also used : BgpNeighbor(org.batfish.datamodel.BgpNeighbor) StaticRoute(org.batfish.datamodel.StaticRoute) Interface(org.batfish.datamodel.Interface)

Example 9 with BgpNeighbor

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

the class Graph method findExportRoutingPolicy.

/*
   * Find the export routing policy for a given edge
   */
@Nullable
public RoutingPolicy findExportRoutingPolicy(String router, Protocol proto, GraphEdge ge) {
    Configuration conf = _configurations.get(router);
    if (proto.isConnected()) {
        return null;
    }
    if (proto.isStatic()) {
        return null;
    }
    if (proto.isOspf()) {
        OspfProcess p = conf.getDefaultVrf().getOspfProcess();
        if (p == null) {
            return null;
        }
        String exp = p.getExportPolicy();
        return conf.getRoutingPolicies().get(exp);
    }
    if (proto.isBgp()) {
        BgpNeighbor n = findBgpNeighbor(ge);
        // if no neighbor (e.g., loopback), or no export policy
        if (n == null || n.getExportPolicy() == null) {
            return null;
        }
        return conf.getRoutingPolicies().get(n.getExportPolicy());
    }
    throw new BatfishException("TODO: findExportRoutingPolicy for " + proto.name());
}
Also used : BgpNeighbor(org.batfish.datamodel.BgpNeighbor) BatfishException(org.batfish.common.BatfishException) Configuration(org.batfish.datamodel.Configuration) OspfProcess(org.batfish.datamodel.OspfProcess) Nullable(javax.annotation.Nullable)

Example 10 with BgpNeighbor

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

the class AbstractionBuilder method createAbstractConfig.

/*
   * Creates a new Configuration from an old one for an abstract router
   * by copying the old configuration, but removing any concrete interfaces,
   * neighbors etc that do not correpond to any abstract neighbors.
   */
private Configuration createAbstractConfig(Set<String> abstractRouters, Configuration conf) {
    Configuration abstractConf = new Configuration(conf.getHostname(), conf.getConfigurationFormat());
    abstractConf.setDnsServers(conf.getDnsServers());
    abstractConf.setDnsSourceInterface(conf.getDnsSourceInterface());
    abstractConf.setDomainName(conf.getDomainName());
    abstractConf.setAuthenticationKeyChains(conf.getAuthenticationKeyChains());
    abstractConf.setIkeGateways(conf.getIkeGateways());
    abstractConf.setDefaultCrossZoneAction(conf.getDefaultCrossZoneAction());
    abstractConf.setIkePolicies(conf.getIkePolicies());
    abstractConf.setIkeProposals(conf.getIkeProposals());
    abstractConf.setDefaultInboundAction(conf.getDefaultInboundAction());
    abstractConf.setIpAccessLists(conf.getIpAccessLists());
    abstractConf.setIp6AccessLists(conf.getIp6AccessLists());
    abstractConf.setRouteFilterLists(conf.getRouteFilterLists());
    abstractConf.setRoute6FilterLists(conf.getRoute6FilterLists());
    abstractConf.setIpsecPolicies(conf.getIpsecPolicies());
    abstractConf.setIpsecProposals(conf.getIpsecProposals());
    abstractConf.setIpsecVpns(conf.getIpsecVpns());
    abstractConf.setLoggingServers(conf.getLoggingServers());
    abstractConf.setLoggingSourceInterface(conf.getLoggingSourceInterface());
    abstractConf.setNormalVlanRange(conf.getNormalVlanRange());
    abstractConf.setNtpServers(conf.getNtpServers());
    abstractConf.setNtpSourceInterface(conf.getNtpSourceInterface());
    abstractConf.setRoles(conf.getRoles());
    abstractConf.setSnmpSourceInterface(conf.getSnmpSourceInterface());
    abstractConf.setSnmpTrapServers(conf.getSnmpTrapServers());
    abstractConf.setTacacsServers(conf.getTacacsServers());
    abstractConf.setTacacsSourceInterface(conf.getTacacsSourceInterface());
    abstractConf.setVendorFamily(conf.getVendorFamily());
    abstractConf.setZones(conf.getZones());
    abstractConf.setCommunityLists(conf.getCommunityLists());
    abstractConf.setRoutingPolicies(conf.getRoutingPolicies());
    abstractConf.setRoute6FilterLists(conf.getRoute6FilterLists());
    SortedSet<Interface> toRetain = new TreeSet<>();
    SortedSet<IpLink> ipNeighbors = new TreeSet<>();
    SortedSet<BgpNeighbor> bgpNeighbors = new TreeSet<>();
    List<GraphEdge> edges = _graph.getEdgeMap().get(conf.getName());
    for (GraphEdge ge : edges) {
        boolean leavesNetwork = (ge.getPeer() == null);
        if (leavesNetwork || (abstractRouters.contains(ge.getRouter()) && abstractRouters.contains(ge.getPeer()))) {
            toRetain.add(ge.getStart());
            Ip start = ge.getStart().getAddress().getIp();
            if (!leavesNetwork) {
                Ip end = ge.getEnd().getAddress().getIp();
                ipNeighbors.add(new IpLink(start, end));
            }
            BgpNeighbor n = _graph.getEbgpNeighbors().get(ge);
            if (n != null) {
                bgpNeighbors.add(n);
            }
        }
    }
    // Update interfaces
    NavigableMap<String, Interface> abstractInterfaces = new TreeMap<>();
    for (Entry<String, Interface> entry : conf.getInterfaces().entrySet()) {
        String name = entry.getKey();
        Interface iface = entry.getValue();
        if (toRetain.contains(iface)) {
            abstractInterfaces.put(name, iface);
        }
    }
    abstractConf.setInterfaces(abstractInterfaces);
    // Update VRFs
    Map<String, Vrf> abstractVrfs = new HashMap<>();
    for (Entry<String, Vrf> entry : conf.getVrfs().entrySet()) {
        String name = entry.getKey();
        Vrf vrf = entry.getValue();
        Vrf abstractVrf = new Vrf(name);
        abstractVrf.setStaticRoutes(vrf.getStaticRoutes());
        abstractVrf.setIsisProcess(vrf.getIsisProcess());
        abstractVrf.setRipProcess(vrf.getRipProcess());
        abstractVrf.setSnmpServer(vrf.getSnmpServer());
        NavigableMap<String, Interface> abstractVrfInterfaces = new TreeMap<>();
        for (Entry<String, Interface> entry2 : vrf.getInterfaces().entrySet()) {
            String iname = entry2.getKey();
            Interface iface = entry2.getValue();
            if (toRetain.contains(iface)) {
                abstractVrfInterfaces.put(iname, iface);
            }
        }
        abstractVrf.setInterfaces(abstractVrfInterfaces);
        abstractVrf.setInterfaceNames(new TreeSet<>(abstractVrfInterfaces.keySet()));
        OspfProcess ospf = vrf.getOspfProcess();
        if (ospf != null) {
            OspfProcess abstractOspf = new OspfProcess();
            abstractOspf.setAreas(ospf.getAreas());
            abstractOspf.setExportPolicy(ospf.getExportPolicy());
            abstractOspf.setReferenceBandwidth(ospf.getReferenceBandwidth());
            abstractOspf.setRouterId(ospf.getRouterId());
            // Copy over neighbors
            Map<IpLink, OspfNeighbor> abstractNeighbors = new HashMap<>();
            if (ospf.getOspfNeighbors() != null) {
                for (Entry<IpLink, OspfNeighbor> entry2 : ospf.getOspfNeighbors().entrySet()) {
                    IpLink link = entry2.getKey();
                    OspfNeighbor neighbor = entry2.getValue();
                    if (ipNeighbors.contains(link)) {
                        abstractNeighbors.put(link, neighbor);
                    }
                }
            }
            abstractOspf.setOspfNeighbors(abstractNeighbors);
            abstractVrf.setOspfProcess(abstractOspf);
        }
        BgpProcess bgp = vrf.getBgpProcess();
        if (bgp != null) {
            BgpProcess abstractBgp = new BgpProcess();
            abstractBgp.setMultipathEbgp(bgp.getMultipathEbgp());
            abstractBgp.setMultipathIbgp(bgp.getMultipathIbgp());
            abstractBgp.setRouterId(bgp.getRouterId());
            abstractBgp.setOriginationSpace(bgp.getOriginationSpace());
            // TODO: set bgp neighbors accordingly
            // Copy over neighbors
            SortedMap<Prefix, BgpNeighbor> abstractBgpNeighbors = new TreeMap<>();
            if (bgp.getNeighbors() != null) {
                for (Entry<Prefix, BgpNeighbor> entry2 : bgp.getNeighbors().entrySet()) {
                    Prefix prefix = entry2.getKey();
                    BgpNeighbor neighbor = entry2.getValue();
                    if (bgpNeighbors.contains(neighbor)) {
                        abstractBgpNeighbors.put(prefix, neighbor);
                    }
                }
            }
            abstractBgp.setNeighbors(abstractBgpNeighbors);
            abstractVrf.setBgpProcess(abstractBgp);
        }
        abstractVrfs.put(name, abstractVrf);
    }
    abstractConf.setVrfs(abstractVrfs);
    return abstractConf;
}
Also used : IpLink(org.batfish.datamodel.IpLink) Configuration(org.batfish.datamodel.Configuration) HashMap(java.util.HashMap) BgpProcess(org.batfish.datamodel.BgpProcess) Ip(org.batfish.datamodel.Ip) Vrf(org.batfish.datamodel.Vrf) Prefix(org.batfish.datamodel.Prefix) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) TreeSet(java.util.TreeSet) OspfNeighbor(org.batfish.datamodel.OspfNeighbor) OspfProcess(org.batfish.datamodel.OspfProcess) TreeMap(java.util.TreeMap) GraphEdge(org.batfish.symbolic.GraphEdge) Interface(org.batfish.datamodel.Interface)

Aggregations

BgpNeighbor (org.batfish.datamodel.BgpNeighbor)23 Ip (org.batfish.datamodel.Ip)15 Prefix (org.batfish.datamodel.Prefix)13 Configuration (org.batfish.datamodel.Configuration)10 BatfishException (org.batfish.common.BatfishException)9 BgpProcess (org.batfish.datamodel.BgpProcess)9 TreeSet (java.util.TreeSet)7 Interface (org.batfish.datamodel.Interface)7 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)5 GraphEdge (org.batfish.symbolic.GraphEdge)5 AsPath (org.batfish.datamodel.AsPath)4 BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)4 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)4 MatchProtocol (org.batfish.datamodel.routing_policy.expr.MatchProtocol)4 BgpAdvertisementType (org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType)3 BgpRoute (org.batfish.datamodel.BgpRoute)3