use of org.batfish.main.Batfish in project batfish by batfish.
the class BdpDataPlanePluginTest method testBgpNeighborReachability.
@Test
public void testBgpNeighborReachability() throws IOException {
// Only connect one neighbor (n2) to core router
SortedMap<String, Configuration> configs = generateNetworkWithDuplicates();
Batfish batfish = BatfishTestUtils.getBatfish(configs, _folder);
DataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
dataPlanePlugin.computeDataPlane(false);
// N2 has proper neighbor relationship
Collection<BgpNeighbor> n2Neighbors = configs.get("n2").getVrfs().get(DEFAULT_VRF_NAME).getBgpProcess().getNeighbors().values();
assertThat(n2Neighbors, hasSize(1));
assertThat(n2Neighbors.iterator().next().getRemoteBgpNeighbor(), is(notNullValue()));
// N1 does not have a full session established, because it's not reachable
Collection<BgpNeighbor> n1Neighbors = configs.get("n1").getVrfs().get(DEFAULT_VRF_NAME).getBgpProcess().getNeighbors().values();
assertThat(n1Neighbors, hasSize(1));
assertThat(n1Neighbors.iterator().next().getRemoteBgpNeighbor(), is(nullValue()));
}
use of org.batfish.main.Batfish in project batfish by batfish.
the class BdpDataPlanePluginTest method testIbgpRejectSameNeighborID.
@Test
public void testIbgpRejectSameNeighborID() throws IOException {
String testrigName = "ibgp-reject-routerid-match";
List<String> configurationNames = ImmutableList.of("r1", "r2", "r3", "r4");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
batfish.computeDataPlane(false);
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
SortedSet<AbstractRoute> r2Routes = routes.get("r2").get(DEFAULT_VRF_NAME);
SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(DEFAULT_VRF_NAME);
Set<Prefix> r2Prefixes = r2Routes.stream().map(r -> r.getNetwork()).collect(Collectors.toSet());
Set<Prefix> r3Prefixes = r3Routes.stream().map(r -> r.getNetwork()).collect(Collectors.toSet());
// 9.9.9.9/32 is the prefix we test with
Prefix r1AdvertisedPrefix = Prefix.parse("9.9.9.9/32");
// Ensure that the prefix is accepted by r2, because router ids are different
assertThat(r1AdvertisedPrefix, isIn(r2Prefixes));
// Ensure that the prefix is rejected by r3, because router ids are the same
assertThat(r1AdvertisedPrefix, not(isIn(r3Prefixes)));
}
use of org.batfish.main.Batfish in project batfish by batfish.
the class BdpDataPlanePluginTest method testIosRtStaticMatchesBdp.
@Test
public void testIosRtStaticMatchesBdp() throws IOException {
String testrigResourcePrefix = TESTRIGS_PREFIX + "ios-rt-static-ad";
List<String> configurationNames = ImmutableList.of("r1");
List<String> routingTableNames = ImmutableList.of("r1");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(testrigResourcePrefix, configurationNames).setRoutingTablesText(testrigResourcePrefix, routingTableNames).build(), _folder);
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
batfish.computeDataPlane(false);
SortedMap<String, RoutesByVrf> environmentRoutes = batfish.loadEnvironmentRoutingTables();
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
Prefix staticRoutePrefix = Prefix.parse("10.0.0.0/8");
SortedSet<AbstractRoute> r1BdpRoutes = routes.get("r1").get(DEFAULT_VRF_NAME);
AbstractRoute r1BdpRoute = r1BdpRoutes.stream().filter(r -> r.getNetwork().equals(staticRoutePrefix)).findFirst().get();
SortedSet<Route> r1EnvironmentRoutes = environmentRoutes.get("r1").get(DEFAULT_VRF_NAME);
Route r1EnvironmentRoute = r1EnvironmentRoutes.stream().filter(r -> r.getNetwork().equals(staticRoutePrefix)).findFirst().get();
assertThat(r1BdpRoute.getAdministrativeCost(), equalTo(r1EnvironmentRoute.getAdministrativeCost()));
assertThat(r1BdpRoute.getMetric(), equalTo(r1EnvironmentRoute.getMetric()));
assertThat(r1BdpRoute.getProtocol(), equalTo(r1EnvironmentRoute.getProtocol()));
}
use of org.batfish.main.Batfish in project batfish by batfish.
the class BdpDataPlanePluginTest method testBgpOscillationRecovery.
private void testBgpOscillationRecovery(MockBdpSettings bdpSettings) throws IOException {
String testrigName = "bgp-oscillation";
List<String> configurationNames = ImmutableList.of("r1", "r2", "r3");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
Settings settings = batfish.getSettings();
settings.setBdpDetail(bdpSettings.getBdpDetail());
settings.setBdpMaxOscillationRecoveryAttempts(bdpSettings.getBdpMaxOscillationRecoveryAttempts());
settings.setBdpMaxRecordedIterations(bdpSettings.getBdpMaxRecordedIterations());
settings.setBdpPrintAllIterations(bdpSettings.getBdpPrintAllIterations());
settings.setBdpPrintOscillatingIterations(bdpSettings.getBdpPrintOscillatingIterations());
settings.setBdpRecordAllIterations(bdpSettings.getBdpRecordAllIterations());
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
/*
* Data plane computation succeeds iff recovery is enabled. If disabled, an exception is thrown
* and should be expected by caller.
*/
batfish.computeDataPlane(false);
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
Prefix bgpPrefix = Prefix.parse("1.1.1.1/32");
SortedSet<AbstractRoute> r2Routes = routes.get("r2").get(DEFAULT_VRF_NAME);
SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(DEFAULT_VRF_NAME);
Stream<AbstractRoute> r2MatchingRoutes = r2Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix));
Stream<AbstractRoute> r3MatchingRoutes = r3Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix));
AbstractRoute r2Route = r2Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix)).findAny().get();
AbstractRoute r3Route = r3Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix)).findAny().get();
String r2NextHop = r2Route.getNextHop();
String r3NextHop = r3Route.getNextHop();
int routesWithR1AsNextHop = 0;
if (r2Route.getNextHop().equals("r1")) {
routesWithR1AsNextHop++;
}
if (r3Route.getNextHop().equals("r1")) {
routesWithR1AsNextHop++;
}
boolean r2AsNextHop = r3NextHop.equals("r2");
boolean r3AsNextHop = r2NextHop.equals("r3");
/*
* Data plane computation should succeed as follows if recovery is enabled.
*/
assertThat(r2MatchingRoutes.count(), equalTo(1L));
assertThat(r3MatchingRoutes.count(), equalTo(1L));
assertThat(routesWithR1AsNextHop, equalTo(1));
assertTrue((r2AsNextHop && !r3AsNextHop) || (!r2AsNextHop && r3AsNextHop));
}
use of org.batfish.main.Batfish in project batfish by batfish.
the class BdpDataPlanePluginTest method testEbgpAcceptSameNeighborID.
@Test
public void testEbgpAcceptSameNeighborID() throws IOException {
String testrigName = "ebgp-accept-routerid-match";
List<String> configurationNames = ImmutableList.of("r1", "r2", "r3");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
batfish.computeDataPlane(false);
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
SortedSet<AbstractRoute> r1Routes = routes.get("r1").get(DEFAULT_VRF_NAME);
SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(DEFAULT_VRF_NAME);
Set<Prefix> r1Prefixes = r1Routes.stream().map(r -> r.getNetwork()).collect(Collectors.toSet());
Set<Prefix> r3Prefixes = r3Routes.stream().map(r -> r.getNetwork()).collect(Collectors.toSet());
Prefix r1Loopback0Prefix = Prefix.parse("1.0.0.1/32");
Prefix r3Loopback0Prefix = Prefix.parse("3.0.0.3/32");
// Ensure that r3loopback was accepted by r1
assertThat(r3Loopback0Prefix, isIn(r1Prefixes));
// Check the other direction (r1loopback is accepted by r3)
assertThat(r1Loopback0Prefix, isIn(r3Prefixes));
}
Aggregations