Search in sources :

Example 11 with StaticRoute

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

the class PropertyChecker method checkRoutingLoop.

/*
   * Checks for routing loops in the network. For efficiency reasons,
   * we only check for loops with routers that use static routes since
   * these can override the usual loop-prevention mechanisms.
   */
public AnswerElement checkRoutingLoop(HeaderQuestion q) {
    Graph graph = new Graph(_batfish);
    // Collect all relevant destinations
    List<Prefix> prefixes = new ArrayList<>();
    graph.getStaticRoutes().forEach((router, ifaceName, srs) -> {
        for (StaticRoute sr : srs) {
            prefixes.add(sr.getNetwork());
        }
    });
    SortedSet<IpWildcard> pfxs = new TreeSet<>();
    for (Prefix prefix : prefixes) {
        pfxs.add(new IpWildcard(prefix));
    }
    q.getHeaderSpace().setDstIps(pfxs);
    // Collect all routers that use static routes as a
    // potential node along a loop
    List<String> routers = new ArrayList<>();
    for (Entry<String, Configuration> entry : graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        if (conf.getDefaultVrf().getStaticRoutes().size() > 0) {
            routers.add(router);
        }
    }
    Encoder enc = new Encoder(_settings, graph, q);
    enc.computeEncoding();
    Context ctx = enc.getCtx();
    EncoderSlice slice = enc.getMainSlice();
    PropertyAdder pa = new PropertyAdder(slice);
    BoolExpr someLoop = ctx.mkBool(false);
    for (String router : routers) {
        BoolExpr hasLoop = pa.instrumentLoop(router);
        someLoop = ctx.mkOr(someLoop, hasLoop);
    }
    enc.add(someLoop);
    VerificationResult result = enc.verify().getFirst();
    return new SmtOneAnswerElement(result);
}
Also used : Context(com.microsoft.z3.Context) BoolExpr(com.microsoft.z3.BoolExpr) StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) ArrayList(java.util.ArrayList) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement) Prefix(org.batfish.datamodel.Prefix) IpWildcard(org.batfish.datamodel.IpWildcard) Graph(org.batfish.symbolic.Graph) TreeSet(java.util.TreeSet)

Example 12 with StaticRoute

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

the class AbstractRibTest method testMultiOverlappingRouteAdd.

/**
 * Check that containsRoute and route collection works as expected in the presence of overlapping
 * routes in the RIB
 */
@Test
public void testMultiOverlappingRouteAdd() {
    // Setup/Test: Add multiple routes with overlapping prefixes
    List<StaticRoute> routes = setupOverlappingRoutes();
    // Assertions
    Set<StaticRoute> collectedRoutes = _rib.getRoutes();
    assertThat(collectedRoutes, hasSize(routes.size()));
    assertThat(_rib.containsRoute(_mostGeneralRoute), is(false));
    for (StaticRoute r : routes) {
        assertThat(_rib.containsRoute(r), is(true));
        assertThat(collectedRoutes, hasItem(r));
    }
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Test(org.junit.Test)

Example 13 with StaticRoute

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

the class AbstractRibTest method testNonOverlappingRouteAdd.

/**
 * Check that containsRoute and route collection works as expected in the presence of
 * non-overlapping routes in the RIB
 */
@Test
public void testNonOverlappingRouteAdd() {
    // Setup
    StaticRoute r1 = new StaticRoute(Prefix.parse("1.1.1.1/32"), Ip.ZERO, null, 0, 0);
    StaticRoute r2 = new StaticRoute(Prefix.parse("128.1.1.1/32"), Ip.ZERO, null, 0, 0);
    // Test:
    _rib.mergeRoute(r1);
    _rib.mergeRoute(r2);
    // Assertions
    // Check that both routes exist
    Set<StaticRoute> collectedRoutes = _rib.getRoutes();
    assertThat(collectedRoutes, hasSize(2));
    assertThat(_rib.containsRoute(r1), is(true));
    assertThat(_rib.containsRoute(r2), is(true));
    // Also check route collection via getRoutes()
    assertThat(collectedRoutes, hasItem(r1));
    assertThat(collectedRoutes, hasItem(r2));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Test(org.junit.Test)

Example 14 with StaticRoute

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

the class VirtualRouterTest method testStaticRibInit.

@Test
public void testStaticRibInit() {
    VirtualRouter vr = makeIosVirtualRouter(null);
    vr.initRibs();
    SortedSet<StaticRoute> routeSet = ImmutableSortedSet.of(new StaticRoute(Prefix.parse("1.1.1.1/32"), Ip.ZERO, null, 1, 0));
    vr._vrf.setStaticRoutes(routeSet);
    // Test
    vr.initStaticRib();
    assertThat(vr._staticRib.getRoutes(), equalTo(routeSet));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Test(org.junit.Test)

Example 15 with StaticRoute

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

Aggregations

StaticRoute (org.batfish.datamodel.StaticRoute)31 Configuration (org.batfish.datamodel.Configuration)17 Interface (org.batfish.datamodel.Interface)14 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)13 Ip (org.batfish.datamodel.Ip)12 Test (org.junit.Test)10 Prefix (org.batfish.datamodel.Prefix)9 ArrayList (java.util.ArrayList)4 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)4 List (java.util.List)3 TreeSet (java.util.TreeSet)3 BatfishException (org.batfish.common.BatfishException)3 IpAccessList (org.batfish.datamodel.IpAccessList)3 NetworkFactory (org.batfish.datamodel.NetworkFactory)3 Vrf (org.batfish.datamodel.Vrf)3 BoolExpr (com.microsoft.z3.BoolExpr)2 TreeMap (java.util.TreeMap)2 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)2 CommunityList (org.batfish.datamodel.CommunityList)2 Conjunction (org.batfish.datamodel.routing_policy.expr.Conjunction)2