Search in sources :

Example 41 with Interface

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

the class VirtualRouter method propagateOspfExternalRoutes.

public boolean propagateOspfExternalRoutes(Map<String, Node> nodes, Topology topology) {
    boolean changed = false;
    String node = _c.getHostname();
    OspfProcess proc = _vrf.getOspfProcess();
    if (proc != null) {
        int admin = RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat());
        SortedSet<Edge> edges = topology.getNodeEdges().get(node);
        if (edges == null) {
            // there are no edges, so OSPF won't produce anything
            return false;
        }
        for (Edge edge : edges) {
            if (!edge.getNode1().equals(node)) {
                continue;
            }
            String connectingInterfaceName = edge.getInt1();
            Interface connectingInterface = _vrf.getInterfaces().get(connectingInterfaceName);
            if (connectingInterface == null) {
                // wrong vrf, so skip
                continue;
            }
            String neighborName = edge.getNode2();
            Node neighbor = nodes.get(neighborName);
            String neighborInterfaceName = edge.getInt2();
            OspfArea area = connectingInterface.getOspfArea();
            Configuration nc = neighbor._c;
            Interface neighborInterface = nc.getInterfaces().get(neighborInterfaceName);
            String neighborVrfName = neighborInterface.getVrfName();
            VirtualRouter neighborVirtualRouter = nodes.get(neighborName)._virtualRouters.get(neighborVrfName);
            OspfArea neighborArea = neighborInterface.getOspfArea();
            if (connectingInterface.getOspfEnabled() && !connectingInterface.getOspfPassive() && neighborInterface.getOspfEnabled() && !neighborInterface.getOspfPassive() && area != null && neighborArea != null && area.getName().equals(neighborArea.getName())) {
                /*
           * We have an ospf neighbor relationship on this edge. So we
           * should add all ospf external type 1(2) routes from this
           * neighbor into our ospf external type 1(2) staging rib. For
           * type 1, the cost of the route increases each time. For type 2,
           * the cost remains constant, but we must keep track of cost to
           * advertiser as a tie-breaker.
           */
                long connectingInterfaceCost = connectingInterface.getOspfCost();
                long incrementalCost = proc.getMaxMetricTransitLinks() != null ? proc.getMaxMetricTransitLinks() : connectingInterfaceCost;
                for (OspfExternalType1Route neighborRoute : neighborVirtualRouter._prevOspfExternalType1Rib.getRoutes()) {
                    long oldArea = neighborRoute.getArea();
                    long connectionArea = area.getName();
                    long newArea;
                    long baseMetric = neighborRoute.getMetric();
                    long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
                    newArea = connectionArea;
                    if (oldArea != OspfRoute.NO_AREA) {
                        Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
                        if (connectionArea != oldArea) {
                            if (connectionArea != 0L && oldArea != 0L) {
                                continue;
                            }
                            if (maxMetricSummaryNetworks != null) {
                                baseMetric = maxMetricSummaryNetworks + neighborRoute.getLsaMetric();
                                baseCostToAdvertiser = maxMetricSummaryNetworks;
                            }
                        }
                    }
                    long newMetric = baseMetric + incrementalCost;
                    long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
                    OspfExternalType1Route newRoute = new OspfExternalType1Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, newMetric, neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
                    if (_ospfExternalType1StagingRib.mergeRoute(newRoute)) {
                        changed = true;
                    }
                }
                for (OspfExternalType2Route neighborRoute : neighborVirtualRouter._prevOspfExternalType2Rib.getRoutes()) {
                    long oldArea = neighborRoute.getArea();
                    long connectionArea = area.getName();
                    long newArea;
                    long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
                    if (oldArea == OspfRoute.NO_AREA) {
                        newArea = connectionArea;
                    } else {
                        newArea = oldArea;
                        Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
                        if (connectionArea != oldArea && maxMetricSummaryNetworks != null) {
                            baseCostToAdvertiser = maxMetricSummaryNetworks;
                        }
                    }
                    long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
                    OspfExternalType2Route newRoute = new OspfExternalType2Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, neighborRoute.getMetric(), neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
                    if (_ospfExternalType2StagingRib.mergeRoute(newRoute)) {
                        changed = true;
                    }
                }
            }
        }
    }
    return changed;
}
Also used : OspfExternalType2Route(org.batfish.datamodel.OspfExternalType2Route) OspfArea(org.batfish.datamodel.OspfArea) Configuration(org.batfish.datamodel.Configuration) OspfProcess(org.batfish.datamodel.OspfProcess) OspfExternalType1Route(org.batfish.datamodel.OspfExternalType1Route) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Example 42 with Interface

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

the class VirtualRouter method initConnectedRib.

/**
 * Initialize the connected RIB -- a RIB containing connected routes (i.e., direct connections to
 * neighbors).
 */
@VisibleForTesting
void initConnectedRib() {
    // Look at all connected interfaces
    for (Interface i : _vrf.getInterfaces().values()) {
        if (i.getActive()) {
            // Create a route for each interface prefix
            for (InterfaceAddress ifaceAddress : i.getAllAddresses()) {
                Prefix prefix = ifaceAddress.getPrefix();
                ConnectedRoute cr = new ConnectedRoute(prefix, i.getName());
                _connectedRib.mergeRoute(cr);
            }
        }
    }
}
Also used : ConnectedRoute(org.batfish.datamodel.ConnectedRoute) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Prefix(org.batfish.datamodel.Prefix) Interface(org.batfish.datamodel.Interface) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 43 with Interface

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

the class BdpEngine method processCurrentNextHopInterfaceEdges.

private boolean processCurrentNextHopInterfaceEdges(BdpDataPlane dp, String currentNodeName, Set<Edge> visitedEdges, List<FlowTraceHop> hopsSoFar, Set<FlowTrace> flowTraces, Flow originalFlow, Flow transformedFlow, Ip dstIp, Set<String> dstIpOwners, @Nullable String nextHopInterfaceName, SortedSet<String> routesForThisNextHopInterface, @Nullable Ip finalNextHopIp, @Nullable NodeInterfacePair nextHopInterface, SortedSet<Edge> edges, boolean arp) {
    boolean continueToNextNextHopInterface = false;
    int unreachableNeighbors = 0;
    int potentialNeighbors = 0;
    for (Edge edge : edges) {
        if (!edge.getNode1().equals(currentNodeName)) {
            continue;
        }
        potentialNeighbors++;
        List<FlowTraceHop> newHops = new ArrayList<>(hopsSoFar);
        Set<Edge> newVisitedEdges = new LinkedHashSet<>(visitedEdges);
        FlowTraceHop newHop = new FlowTraceHop(edge, routesForThisNextHopInterface, hopFlow(originalFlow, transformedFlow));
        newVisitedEdges.add(edge);
        newHops.add(newHop);
        /*
       * Check to see whether neighbor would refrain from sending ARP reply
       * (NEIGHBOR_UNREACHABLE)
       *
       * This occurs if:
       *
       * - Using interface-only route
       *
       * AND
       *
       * - Neighbor does not own arpIp
       *
       * AND EITHER
       *
       * -- Neighbor not using proxy-arp
       *
       * - OR
       *
       * -- Subnet of neighbor's receiving-interface contains arpIp
       */
        if (arp) {
            Ip arpIp;
            Set<String> arpIpOwners;
            if (finalNextHopIp == null) {
                arpIp = dstIp;
                arpIpOwners = dstIpOwners;
            } else {
                arpIp = finalNextHopIp;
                arpIpOwners = dp._ipOwners.get(arpIp);
            }
            // using interface-only route
            String node2 = edge.getNode2();
            if (arpIpOwners == null || !arpIpOwners.contains(node2)) {
                // neighbor does not own arpIp
                String int2Name = edge.getInt2();
                Interface int2 = dp._nodes.get(node2)._c.getInterfaces().get(int2Name);
                boolean neighborUnreachable = false;
                Boolean proxyArp = int2.getProxyArp();
                if (proxyArp == null || !proxyArp) {
                    // TODO: proxyArp probably shouldn't be null
                    neighborUnreachable = true;
                } else {
                    for (InterfaceAddress address : int2.getAllAddresses()) {
                        if (address.getPrefix().containsIp(arpIp)) {
                            neighborUnreachable = true;
                            break;
                        }
                    }
                }
                if (neighborUnreachable) {
                    unreachableNeighbors++;
                    continue;
                }
            }
        }
        if (visitedEdges.contains(edge)) {
            FlowTrace trace = new FlowTrace(FlowDisposition.LOOP, newHops, FlowDisposition.LOOP.toString());
            flowTraces.add(trace);
            potentialNeighbors--;
            continue;
        }
        String nextNodeName = edge.getNode2();
        // now check output filter and input filter
        if (nextHopInterfaceName != null) {
            IpAccessList outFilter = dp._nodes.get(currentNodeName)._c.getInterfaces().get(nextHopInterfaceName).getOutgoingFilter();
            if (outFilter != null) {
                FlowDisposition disposition = FlowDisposition.DENIED_OUT;
                boolean denied = flowTraceDeniedHelper(flowTraces, originalFlow, transformedFlow, newHops, outFilter, disposition);
                if (denied) {
                    potentialNeighbors--;
                    continue;
                }
            }
        }
        IpAccessList inFilter = dp._nodes.get(nextNodeName)._c.getInterfaces().get(edge.getInt2()).getIncomingFilter();
        if (inFilter != null) {
            FlowDisposition disposition = FlowDisposition.DENIED_IN;
            boolean denied = flowTraceDeniedHelper(flowTraces, originalFlow, transformedFlow, newHops, inFilter, disposition);
            if (denied) {
                potentialNeighbors--;
                continue;
            }
        }
        // recurse
        collectFlowTraces(dp, nextNodeName, newVisitedEdges, newHops, flowTraces, originalFlow, transformedFlow);
    }
    if (arp && unreachableNeighbors > 0 && unreachableNeighbors == potentialNeighbors) {
        FlowTrace trace = neighborUnreachableTrace(hopsSoFar, nextHopInterface, routesForThisNextHopInterface, originalFlow, transformedFlow);
        flowTraces.add(trace);
        continueToNextNextHopInterface = true;
    }
    return continueToNextNextHopInterface;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) ArrayList(java.util.ArrayList) FlowDisposition(org.batfish.datamodel.FlowDisposition) FlowTraceHop(org.batfish.datamodel.FlowTraceHop) FlowTrace(org.batfish.datamodel.FlowTrace) IpAccessList(org.batfish.datamodel.IpAccessList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Example 44 with Interface

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

the class InterfacesSpecifierTest method matchesName.

@Test
public void matchesName() {
    InterfacesSpecifier specifier = new InterfacesSpecifier("name:Loopback.*");
    Interface loopbackInterface = new Interface("Loopback0");
    Interface nonLoopbackInterface = new Interface("Ethetnet0/0");
    assertThat(specifier.matches(loopbackInterface), equalTo(true));
    assertThat(specifier.matches(nonLoopbackInterface), equalTo(false));
}
Also used : Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 45 with Interface

use of org.batfish.datamodel.Interface 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)

Aggregations

Interface (org.batfish.datamodel.Interface)68 Configuration (org.batfish.datamodel.Configuration)42 Ip (org.batfish.datamodel.Ip)26 Edge (org.batfish.datamodel.Edge)21 Prefix (org.batfish.datamodel.Prefix)20 Test (org.junit.Test)19 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)18 Vrf (org.batfish.datamodel.Vrf)18 HashMap (java.util.HashMap)17 IpAccessList (org.batfish.datamodel.IpAccessList)16 Topology (org.batfish.datamodel.Topology)14 ArrayList (java.util.ArrayList)13 List (java.util.List)13 StaticRoute (org.batfish.datamodel.StaticRoute)13 HashSet (java.util.HashSet)12 Set (java.util.Set)12 BatfishException (org.batfish.common.BatfishException)12 Map (java.util.Map)11 TreeSet (java.util.TreeSet)10 SortedSet (java.util.SortedSet)9