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);
}
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));
}
}
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));
}
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));
}
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;
}
Aggregations