Search in sources :

Example 1 with OspfIntraAreaRoute

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

the class VirtualRouter method propagateOspfIntraAreaRoute.

boolean propagateOspfIntraAreaRoute(OspfIntraAreaRoute neighborRoute, long incrementalCost, Interface neighborInterface, int adminCost, long areaNum) {
    long newCost = neighborRoute.getMetric() + incrementalCost;
    Ip nextHopIp = neighborInterface.getAddress().getIp();
    OspfIntraAreaRoute newRoute = new OspfIntraAreaRoute(neighborRoute.getNetwork(), nextHopIp, adminCost, newCost, areaNum);
    return neighborRoute.getArea() == areaNum && _ospfIntraAreaStagingRib.mergeRoute(newRoute);
}
Also used : Ip(org.batfish.datamodel.Ip) OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute)

Example 2 with OspfIntraAreaRoute

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

the class VirtualRouter method initIntraAreaOspfRoutes.

/**
 * Initialize Intra-area OSPF routes from the interface prefixes
 */
private void initIntraAreaOspfRoutes() {
    OspfProcess proc = _vrf.getOspfProcess();
    if (proc == null) {
        // nothing to do
        return;
    }
    // init intra-area routes from connected routes
    // For each interface within an OSPF area and each interface prefix,
    // construct a new OSPF-IA route. Put it in the IA RIB.
    proc.getAreas().forEach((areaNum, area) -> {
        for (String ifaceName : area.getInterfaces()) {
            Interface iface = _c.getInterfaces().get(ifaceName);
            if (iface.getActive()) {
                Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream().map(InterfaceAddress::getPrefix).collect(Collectors.toSet());
                int interfaceOspfCost = iface.getOspfCost();
                for (Prefix prefix : allNetworkPrefixes) {
                    long cost = interfaceOspfCost;
                    boolean stubNetwork = iface.getOspfPassive() || iface.getOspfPointToPoint();
                    if (stubNetwork) {
                        if (proc.getMaxMetricStubNetworks() != null) {
                            cost = proc.getMaxMetricStubNetworks();
                        }
                    } else if (proc.getMaxMetricTransitLinks() != null) {
                        cost = proc.getMaxMetricTransitLinks();
                    }
                    OspfIntraAreaRoute route = new OspfIntraAreaRoute(prefix, null, RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat()), cost, areaNum);
                    _ospfIntraAreaRib.mergeRoute(route);
                }
            }
        }
    });
}
Also used : OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) OspfProcess(org.batfish.datamodel.OspfProcess) Prefix(org.batfish.datamodel.Prefix) Interface(org.batfish.datamodel.Interface)

Example 3 with OspfIntraAreaRoute

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

the class AbstractRibTest method testGetRoutesWithReplacement.

/**
 * Check that getRoutes works as expected even when routes replace other routes based on
 * preference
 */
@Test
public void testGetRoutesWithReplacement() {
    // Use OSPF RIBs for this, as routes with better metric can replace other routes
    OspfIntraAreaRib rib = new OspfIntraAreaRib(null);
    Prefix prefix = Prefix.parse("1.1.1.1/32");
    rib.mergeRoute(new OspfIntraAreaRoute(prefix, null, 100, 30, 1));
    assertThat(rib.getRoutes(), hasSize(1));
    // This new route replaces old route
    OspfIntraAreaRoute newRoute = new OspfIntraAreaRoute(prefix, null, 100, 10, 1);
    rib.mergeRoute(newRoute);
    assertThat(rib.getRoutes(), contains(newRoute));
    // Add completely new route and check that the size increases
    rib.mergeRoute(new OspfIntraAreaRoute(Prefix.parse("2.2.2.2/32"), null, 100, 30, 1));
    assertThat(rib.getRoutes(), hasSize(2));
}
Also used : OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) Prefix(org.batfish.datamodel.Prefix) Test(org.junit.Test)

Example 4 with OspfIntraAreaRoute

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

the class VirtualRouterTest method testOSPFPassiveInterfaceRejection.

/**
 * Ensure no route propagation when the interfaces are disabled or passive
 */
@Test
public void testOSPFPassiveInterfaceRejection() {
    // Setup
    String testRouterName = "R1";
    String exportingRouterName = "R2";
    String exportingRouterInterfaceName = "Ethernet1";
    Map<String, Node> nodes = makeIosRouters(testRouterName, exportingRouterName);
    Map<String, VirtualRouter> routers = nodes.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue()._virtualRouters.get(Configuration.DEFAULT_VRF_NAME)));
    VirtualRouter testRouter = routers.get(testRouterName);
    VirtualRouter exportingRouter = routers.get(exportingRouterName);
    testRouter.initRibs();
    exportingRouter.initRibs();
    addInterfaces(testRouter._c, exampleInterfaceAddresses);
    addInterfaces(exportingRouter._c, ImmutableMap.of(exportingRouterInterfaceName, new InterfaceAddress("10.4.0.0/16")));
    int adminCost = RoutingProtocol.OSPF.getDefaultAdministrativeCost(testRouter._c.getConfigurationFormat());
    Prefix prefix = Prefix.parse("7.7.7.0/24");
    OspfIntraAreaRoute route = new OspfIntraAreaRoute(prefix, new Ip("7.7.1.1"), adminCost, 20, 1);
    exportingRouter._ospfIntraAreaRib.mergeRoute(route);
    // Set interaces on router 1 to be OSPF passive
    testRouter._c.getInterfaces().forEach((name, iface) -> iface.setActive(false));
    // Test 1
    testRouter.propagateOspfInternalRoutesFromNeighbor(testRouter._vrf.getOspfProcess(), nodes.get("R2"), testRouter._c.getInterfaces().firstEntry().getValue(), exportingRouter._c.getInterfaces().get(exportingRouterInterfaceName), adminCost);
    assertThat(testRouter._ospfInterAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfInterAreaRoute.class)));
    assertThat(testRouter._ospfIntraAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfIntraAreaRoute.class)));
    // Flip interfaces on router 2 to be passive now
    testRouter._c.getInterfaces().forEach((name, iface) -> iface.setActive(true));
    exportingRouter._c.getInterfaces().forEach((name, iface) -> iface.setActive(false));
    // Test 2
    testRouter.propagateOspfInternalRoutesFromNeighbor(testRouter._vrf.getOspfProcess(), nodes.get("R2"), testRouter._c.getInterfaces().firstEntry().getValue(), exportingRouter._c.getInterfaces().get(exportingRouterInterfaceName), adminCost);
    assertThat(testRouter._ospfInterAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfInterAreaRoute.class)));
    assertThat(testRouter._ospfIntraAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfIntraAreaRoute.class)));
}
Also used : OspfExternalType2Route(org.batfish.datamodel.OspfExternalType2Route) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) BgpAdvertisementMatchers.hasDestinationIp(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasDestinationIp) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) BgpAdvertisementMatchers.hasOriginatorIp(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasOriginatorIp) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Interface(org.batfish.datamodel.Interface) Assert.assertThat(org.junit.Assert.assertThat) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) OspfRoute(org.batfish.datamodel.OspfRoute) Vrf(org.batfish.datamodel.Vrf) Statement(org.batfish.datamodel.routing_policy.statement.Statement) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) RipProcess(org.batfish.datamodel.RipProcess) BgpAdvertisementMatchers.hasSourceIp(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasSourceIp) Set(java.util.Set) RipRoute(org.batfish.datamodel.RipRoute) Collectors(java.util.stream.Collectors) OriginType(org.batfish.datamodel.OriginType) AsPath(org.batfish.datamodel.AsPath) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ConnectedRoute(org.batfish.datamodel.ConnectedRoute) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Entry(java.util.Map.Entry) Matchers.is(org.hamcrest.Matchers.is) OspfInternalRoute(org.batfish.datamodel.OspfInternalRoute) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) Ip(org.batfish.datamodel.Ip) BatfishTestUtils(org.batfish.main.BatfishTestUtils) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) Statements(org.batfish.datamodel.routing_policy.statement.Statements) CoreMatchers.not(org.hamcrest.CoreMatchers.not) BgpAdvertisementMatchers.hasNetwork(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasNetwork) BgpProcess(org.batfish.datamodel.BgpProcess) SetOrigin(org.batfish.datamodel.routing_policy.statement.SetOrigin) HashSet(java.util.HashSet) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) LiteralOrigin(org.batfish.datamodel.routing_policy.expr.LiteralOrigin) ImmutableList(com.google.common.collect.ImmutableList) AbstractRoute(org.batfish.datamodel.AbstractRoute) Configuration(org.batfish.datamodel.Configuration) BgpRoute(org.batfish.datamodel.BgpRoute) LinkedHashSet(java.util.LinkedHashSet) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BgpAdvertisementType(org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType) NetworkFactory(org.batfish.datamodel.NetworkFactory) StaticRoute(org.batfish.datamodel.StaticRoute) Route(org.batfish.datamodel.Route) OspfExternalType1Route(org.batfish.datamodel.OspfExternalType1Route) Test(org.junit.Test) IsEmptyIterable.emptyIterableOf(org.hamcrest.collection.IsEmptyIterable.emptyIterableOf) RipInternalRoute(org.batfish.datamodel.RipInternalRoute) OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute) BgpAdvertisementMatchers.hasType(org.batfish.datamodel.matchers.BgpAdvertisementMatchers.hasType) Prefix(org.batfish.datamodel.Prefix) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) 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) Prefix(org.batfish.datamodel.Prefix) Test(org.junit.Test)

Example 5 with OspfIntraAreaRoute

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

Aggregations

OspfIntraAreaRoute (org.batfish.datamodel.OspfIntraAreaRoute)6 Prefix (org.batfish.datamodel.Prefix)4 OspfInterAreaRoute (org.batfish.datamodel.OspfInterAreaRoute)3 Interface (org.batfish.datamodel.Interface)2 Ip (org.batfish.datamodel.Ip)2 OspfArea (org.batfish.datamodel.OspfArea)2 OspfProcess (org.batfish.datamodel.OspfProcess)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 Collectors (java.util.stream.Collectors)1