Search in sources :

Example 1 with OspfInterAreaRoute

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

the class VirtualRouter method stageOspfInterAreaRoute.

/**
 * Construct an OSPF Inter-Area route and put into our staging rib. Note, no route validity checks
 * are performed, (i.e., whether the route should even go into the staging rib). {@link
 * #propagateOspfInternalRoutesFromNeighbor} takes care of such logic.
 *
 * @param neighborRoute the route to propagate
 * @param nextHopIp nextHopIp for this route (the neighbor's IP)
 * @param incrementalCost OSPF cost of the interface from which this route came (added to route
 *     cost)
 * @param adminCost OSPF administrative distance
 * @param areaNum area number of the route
 * @return True if the route was added to the inter-area staging RIB
 */
@VisibleForTesting
boolean stageOspfInterAreaRoute(OspfInternalRoute neighborRoute, Long maxMetricSummaryNetworks, Ip nextHopIp, long incrementalCost, int adminCost, long areaNum) {
    long newCost;
    if (maxMetricSummaryNetworks != null) {
        newCost = maxMetricSummaryNetworks + incrementalCost;
    } else {
        newCost = neighborRoute.getMetric() + incrementalCost;
    }
    OspfInterAreaRoute newRoute = new OspfInterAreaRoute(neighborRoute.getNetwork(), nextHopIp, adminCost, newCost, areaNum);
    return _ospfInterAreaStagingRib.mergeRoute(newRoute);
}
Also used : OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with OspfInterAreaRoute

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

the class VirtualRouter method computeInterAreaSummaries.

boolean computeInterAreaSummaries() {
    OspfProcess proc = _vrf.getOspfProcess();
    boolean changed = false;
    // Ensure we have a running OSPF process on the VRF, otherwise bail.
    if (proc == null) {
        return false;
    }
    // Admin cost for the given protocol
    int admin = RoutingProtocol.OSPF_IA.getSummaryAdministrativeCost(_c.getConfigurationFormat());
    // Determine whether to use min metric by default, based on RFC1583 compatibility setting.
    // Routers (at least Cisco and Juniper) default to min metric unless using RFC2328 with
    // RFC1583 compatibility explicitly disabled, in which case they default to max.
    boolean useMin = MoreObjects.firstNonNull(proc.getRfc1583Compatible(), true);
    // Compute summaries for each area
    for (Entry<Long, OspfArea> e : proc.getAreas().entrySet()) {
        long areaNum = e.getKey();
        OspfArea area = e.getValue();
        for (Entry<Prefix, OspfAreaSummary> e2 : area.getSummaries().entrySet()) {
            Prefix prefix = e2.getKey();
            OspfAreaSummary summary = e2.getValue();
            // Only advertised summaries can contribute
            if (!summary.getAdvertised()) {
                continue;
            }
            Long metric = summary.getMetric();
            if (summary.getMetric() == null) {
                // No metric was configured; compute it from any possible contributing routes.
                for (OspfIntraAreaRoute contributingRoute : _ospfIntraAreaRib.getRoutes()) {
                    metric = computeUpdatedOspfSummaryMetric(contributingRoute, prefix, metric, areaNum, useMin);
                }
                for (OspfInterAreaRoute contributingRoute : _ospfInterAreaRib.getRoutes()) {
                    metric = computeUpdatedOspfSummaryMetric(contributingRoute, prefix, metric, areaNum, useMin);
                }
            }
            // No routes contributed to the summary, nothing to construct
            if (metric == null) {
                continue;
            }
            // Non-null metric means we generate a new summary and put it in the RIB
            OspfInterAreaRoute summaryRoute = new OspfInterAreaRoute(prefix, Ip.ZERO, admin, metric, areaNum);
            if (_ospfInterAreaStagingRib.mergeRoute(summaryRoute)) {
                changed = true;
            }
        }
    }
    return changed;
}
Also used : OspfArea(org.batfish.datamodel.OspfArea) OspfAreaSummary(org.batfish.datamodel.OspfAreaSummary) OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute) OspfProcess(org.batfish.datamodel.OspfProcess) Prefix(org.batfish.datamodel.Prefix)

Example 3 with OspfInterAreaRoute

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

the class VirtualRouter method propagateOspfInternalRoutesFromNeighbor.

/**
 * Propagate OSPF Internal routes from a single neighbor.
 *
 * @param proc The receiving OSPF process
 * @param neighbor the neighbor
 * @param connectingInterface interface on which we are connected to the neighbor
 * @param neighborInterface interface that the neighbor uses to connect to us
 * @param adminCost route administrative distance
 * @return true if new routes have been added to our staging RIB
 */
boolean propagateOspfInternalRoutesFromNeighbor(OspfProcess proc, Node neighbor, Interface connectingInterface, Interface neighborInterface, int adminCost) {
    OspfArea area = connectingInterface.getOspfArea();
    OspfArea neighborArea = neighborInterface.getOspfArea();
    // Ensure that the link (i.e., both interfaces) has OSPF enabled and OSPF areas are set
    if (!connectingInterface.getOspfEnabled() || connectingInterface.getOspfPassive() || !neighborInterface.getOspfEnabled() || neighborInterface.getOspfPassive() || area == null || neighborArea == null || !area.getName().equals(neighborArea.getName())) {
        return false;
    }
    /*
     * An OSPF neighbor relationship exists on this edge. So we examine all intra- and inter-area
     * routes belonging to the neighbor to see what should be propagated to this router. We add the
     * incremental cost associated with our settings and the connecting interface, and use the
     * neighborInterface's address as the next hop ip.
     */
    int connectingInterfaceCost = connectingInterface.getOspfCost();
    long incrementalCost = proc.getMaxMetricTransitLinks() != null ? proc.getMaxMetricTransitLinks() : connectingInterfaceCost;
    Long areaNum = area.getName();
    VirtualRouter neighborVirtualRouter = neighbor._virtualRouters.get(neighborInterface.getVrfName());
    boolean changed = false;
    for (OspfIntraAreaRoute neighborRoute : neighborVirtualRouter._ospfIntraAreaRib.getRoutes()) {
        changed |= propagateOspfIntraAreaRoute(neighborRoute, incrementalCost, neighborInterface, adminCost, areaNum);
        changed |= propagateOspfInterAreaRouteFromIntraAreaRoute(neighbor, neighborRoute, incrementalCost, neighborInterface, adminCost, areaNum);
    }
    for (OspfInterAreaRoute neighborRoute : neighborVirtualRouter._ospfInterAreaRib.getRoutes()) {
        changed |= propagateOspfInterAreaRouteFromInterAreaRoute(neighbor, neighborRoute, incrementalCost, neighborInterface, adminCost, areaNum);
    }
    return changed;
}
Also used : OspfArea(org.batfish.datamodel.OspfArea) OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute)

Example 4 with OspfInterAreaRoute

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

the class VirtualRouterTest method testStageOSPFInterAreaRoute.

/**
 * Test that staging of a single OSPF Inter-Area route works as expected
 */
@Test
public void testStageOSPFInterAreaRoute() {
    VirtualRouter vr = makeIosVirtualRouter(null);
    vr.initRibs();
    int admin = 50;
    int metric = 100;
    long area = 1L;
    Prefix prefix = Prefix.parse("7.7.7.0/24");
    OspfInterAreaRoute iaroute = new OspfInterAreaRoute(prefix, new Ip("7.7.1.1"), admin, metric, area);
    // Test
    Ip newNextHop = new Ip("10.2.1.1");
    vr.stageOspfInterAreaRoute(iaroute, null, newNextHop, 10, admin, area);
    // Check what's in the RIB is correct.
    // Note the new nextHopIP and the increased metric on the new route.
    assertThat(vr._ospfInterAreaStagingRib.getRoutes(), contains(new OspfInterAreaRoute(prefix, newNextHop, admin, metric + 10, area)));
    assertThat(vr._ospfInterAreaStagingRib.getRoutes(), not(contains(iaroute)));
}
Also used : BgpAdvertisementMatchers.hasDestinationIp(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasDestinationIp) BgpAdvertisementMatchers.hasOriginatorIp(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasOriginatorIp) BgpAdvertisementMatchers.hasSourceIp(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasSourceIp) Ip(org.batfish.datamodel.Ip) OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute) Prefix(org.batfish.datamodel.Prefix) Test(org.junit.Test)

Example 5 with OspfInterAreaRoute

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

the class VirtualRouterTest method testGetBetterOspfRouteMetric.

@Test
public void testGetBetterOspfRouteMetric() {
    Prefix ospfInterAreaRoutePrefix = Prefix.parse("1.1.1.1/24");
    long definedMetric = 5;
    long definedArea = 1;
    OspfInterAreaRoute route = new OspfInterAreaRoute(ospfInterAreaRoutePrefix, Ip.MAX, RoutingProtocol.OSPF_IA.getDefaultAdministrativeCost(FORMAT), definedMetric, 0);
    // The route is in the prefix and existing metric is null, so return the route's metric
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(route, Prefix.ZERO, null, definedArea, true), equalTo(definedMetric));
    // Return the lower metric if the existing not null and using old RFC
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(route, Prefix.ZERO, 10L, definedArea, true), equalTo(definedMetric));
    // Return the higher metric if the existing metric is not null and using new RFC
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(route, Prefix.ZERO, 10L, definedArea, false), equalTo(10L));
    // The route is in the prefix but the existing metric is lower, so return the existing metric
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(route, Prefix.ZERO, 4L, definedArea, true), equalTo(4L));
    // The route is in the prefix but the existing metric is lower, so return the existing metric
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(route, Prefix.ZERO, 4L, definedArea, false), equalTo(definedMetric));
    // The route is not in the area's prefix, return the current metric
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(route, Prefix.parse("2.0.0.0/8"), 4L, definedArea, true), equalTo(4L));
    OspfInterAreaRoute sameAreaRoute = new OspfInterAreaRoute(ospfInterAreaRoutePrefix, Ip.MAX, RoutingProtocol.OSPF_IA.getDefaultAdministrativeCost(FORMAT), definedMetric, // the area is the same as definedArea
    1);
    // Thus the metric should remain null
    assertThat(VirtualRouter.computeUpdatedOspfSummaryMetric(sameAreaRoute, Prefix.ZERO, null, definedArea, true), equalTo(null));
}
Also used : OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute) Prefix(org.batfish.datamodel.Prefix) Test(org.junit.Test)

Aggregations

OspfInterAreaRoute (org.batfish.datamodel.OspfInterAreaRoute)5 Prefix (org.batfish.datamodel.Prefix)3 OspfArea (org.batfish.datamodel.OspfArea)2 OspfIntraAreaRoute (org.batfish.datamodel.OspfIntraAreaRoute)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Ip (org.batfish.datamodel.Ip)1 OspfAreaSummary (org.batfish.datamodel.OspfAreaSummary)1 OspfProcess (org.batfish.datamodel.OspfProcess)1 BgpAdvertisementMatchers.hasDestinationIp (org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasDestinationIp)1 BgpAdvertisementMatchers.hasOriginatorIp (org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasOriginatorIp)1 BgpAdvertisementMatchers.hasSourceIp (org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasSourceIp)1