Search in sources :

Example 81 with Prefix

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

the class VirtualRouter method isOspfInterAreaFromInterAreaPropagationAllowed.

private static boolean isOspfInterAreaFromInterAreaPropagationAllowed(long areaNum, Node neighbor, OspfInternalRoute neighborRoute, OspfArea neighborArea) {
    long neighborRouteAreaNum = neighborRoute.getArea();
    // May only propagate to or from area 0
    if (areaNum != neighborRouteAreaNum && areaNum != 0L && neighborRouteAreaNum != 0L) {
        return false;
    }
    Prefix neighborRouteNetwork = neighborRoute.getNetwork();
    String neighborSummaryFilterName = neighborArea.getSummaryFilter();
    boolean hasSummaryFilter = neighborSummaryFilterName != null;
    boolean allowed = !hasSummaryFilter;
    // If there is a summary filter, run the route through it
    if (hasSummaryFilter) {
        RouteFilterList neighborSummaryFilter = neighbor._c.getRouteFilterLists().get(neighborSummaryFilterName);
        allowed = neighborSummaryFilter.permits(neighborRouteNetwork);
    }
    return allowed;
}
Also used : RouteFilterList(org.batfish.datamodel.RouteFilterList) Prefix(org.batfish.datamodel.Prefix)

Example 82 with Prefix

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

the class VirtualRouter method computeUpdatedOspfSummaryMetric.

/**
 * Decides whether the current OSPF summary route metric needs to be changed based on the given
 * route's metric.
 *
 * <p>Routes from the same area or outside of areaPrefix have no effect on the summary metric.
 *
 * @param route The route in question, whose metric is considered
 * @param areaPrefix The Ip prefix of the OSPF area
 * @param currentMetric The current summary metric for the area
 * @param areaNum Area number.
 * @param useMin Whether to use the older RFC 1583 computation, which takes the minimum of metrics
 *     as opposed to the newer RFC 2328, which uses the maximum
 * @return the newly computed summary metric.
 */
@Nullable
static Long computeUpdatedOspfSummaryMetric(OspfInternalRoute route, Prefix areaPrefix, @Nullable Long currentMetric, long areaNum, boolean useMin) {
    Prefix contributingRoutePrefix = route.getNetwork();
    // Only update metric for different areas and if the area prefix contains the route prefix
    if (areaNum == route.getArea() || !areaPrefix.containsPrefix(contributingRoutePrefix)) {
        return currentMetric;
    }
    long contributingRouteMetric = route.getMetric();
    // Definitely update if we have no previous metric
    if (currentMetric == null) {
        return contributingRouteMetric;
    }
    // RFC1583 compatibility explicitly disabled, in which case they default to max.
    if (useMin) {
        return Math.min(currentMetric, contributingRouteMetric);
    }
    return Math.max(currentMetric, contributingRouteMetric);
}
Also used : Prefix(org.batfish.datamodel.Prefix) Nullable(javax.annotation.Nullable)

Example 83 with Prefix

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

the class VirtualRouter method initBaseRipRoutes.

/**
 * Initialize RIP routes from the interface prefixes
 */
@VisibleForTesting
void initBaseRipRoutes() {
    if (_vrf.getRipProcess() == null) {
        // nothing to do
        return;
    }
    // init internal routes from connected routes
    for (String ifaceName : _vrf.getRipProcess().getInterfaces()) {
        Interface iface = _vrf.getInterfaces().get(ifaceName);
        if (iface.getActive()) {
            Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream().map(InterfaceAddress::getPrefix).collect(Collectors.toSet());
            long cost = RipProcess.DEFAULT_RIP_COST;
            for (Prefix prefix : allNetworkPrefixes) {
                RipInternalRoute route = new RipInternalRoute(prefix, null, RoutingProtocol.RIP.getDefaultAdministrativeCost(_c.getConfigurationFormat()), cost);
                _ripInternalRib.mergeRoute(route);
            }
        }
    }
}
Also used : RipInternalRoute(org.batfish.datamodel.RipInternalRoute) Prefix(org.batfish.datamodel.Prefix) Interface(org.batfish.datamodel.Interface) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 84 with Prefix

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

the class VirtualRouter method activateStaticRoutes.

/**
 * Re-activate static routes at the beginning of an iteration. Directly adds a static route to the
 * main RIB if the route's next-hop-ip matches routes from the previous iterations.
 */
boolean activateStaticRoutes() {
    boolean changed = false;
    for (StaticRoute sr : _staticRib.getRoutes()) {
        // See if we had (in the previous RIB) any routes matching this route's next hop IP
        Set<AbstractRoute> matchingRoutes = _prevMainRib.longestPrefixMatch(sr.getNextHopIp());
        Prefix staticRoutePrefix = sr.getNetwork();
        for (AbstractRoute matchingRoute : matchingRoutes) {
            Prefix matchingRoutePrefix = matchingRoute.getNetwork();
            // contain this static route's prefix
            if (!matchingRoutePrefix.containsPrefix(staticRoutePrefix)) {
                changed |= _mainRib.mergeRoute(sr);
                // break out of the inner loop but continue processing static routes
                break;
            }
        }
    }
    return changed;
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) StaticRoute(org.batfish.datamodel.StaticRoute) Prefix(org.batfish.datamodel.Prefix)

Example 85 with Prefix

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

the class VirtualRouter method isOspfInterAreaFromIntraAreaPropagationAllowed.

private static boolean isOspfInterAreaFromIntraAreaPropagationAllowed(long areaNum, Node neighbor, OspfInternalRoute neighborRoute, OspfArea neighborArea) {
    long neighborRouteAreaNum = neighborRoute.getArea();
    // May only propagate to or from area 0
    if (areaNum == neighborRouteAreaNum || (areaNum != 0L && neighborRouteAreaNum != 0L)) {
        return false;
    }
    Prefix neighborRouteNetwork = neighborRoute.getNetwork();
    String neighborSummaryFilterName = neighborArea.getSummaryFilter();
    boolean hasSummaryFilter = neighborSummaryFilterName != null;
    boolean allowed = !hasSummaryFilter;
    // If there is a summary filter, run the route through it
    if (hasSummaryFilter) {
        RouteFilterList neighborSummaryFilter = neighbor._c.getRouteFilterLists().get(neighborSummaryFilterName);
        allowed = neighborSummaryFilter.permits(neighborRouteNetwork);
    }
    return allowed;
}
Also used : RouteFilterList(org.batfish.datamodel.RouteFilterList) Prefix(org.batfish.datamodel.Prefix)

Aggregations

Prefix (org.batfish.datamodel.Prefix)133 Ip (org.batfish.datamodel.Ip)53 Configuration (org.batfish.datamodel.Configuration)33 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)29 Interface (org.batfish.datamodel.Interface)28 BatfishException (org.batfish.common.BatfishException)22 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)20 SubRange (org.batfish.datamodel.SubRange)19 HashMap (java.util.HashMap)18 StaticRoute (org.batfish.datamodel.StaticRoute)18 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)17 BgpProcess (org.batfish.datamodel.BgpProcess)17 SortedSet (java.util.SortedSet)16 TreeSet (java.util.TreeSet)16 AbstractRoute (org.batfish.datamodel.AbstractRoute)16 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)16 TreeMap (java.util.TreeMap)14 HashSet (java.util.HashSet)13