Search in sources :

Example 16 with Batfish

use of org.batfish.main.Batfish in project batfish by batfish.

the class BdpDataPlanePluginTest method testComputeFixedPoint.

@Test(timeout = 5000)
public void testComputeFixedPoint() throws IOException {
    SortedMap<String, Configuration> configurations = new TreeMap<>();
    // creating configurations with no vrfs
    configurations.put("h1", BatfishTestUtils.createTestConfiguration("h1", ConfigurationFormat.HOST, "eth0"));
    configurations.put("h2", BatfishTestUtils.createTestConfiguration("h2", ConfigurationFormat.HOST, "e0"));
    Batfish batfish = BatfishTestUtils.getBatfish(configurations, _folder);
    BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
    dataPlanePlugin.initialize(batfish);
    // Test that compute Data Plane finishes in a finite time
    dataPlanePlugin.computeDataPlane(false);
}
Also used : Configuration(org.batfish.datamodel.Configuration) Matchers.containsString(org.hamcrest.Matchers.containsString) TreeMap(java.util.TreeMap) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 17 with Batfish

use of org.batfish.main.Batfish in project batfish by batfish.

the class BdpDataPlanePluginTest method testBgpOscillation.

@Test
public void testBgpOscillation() 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);
    batfish.getSettings().setBdpMaxOscillationRecoveryAttempts(0);
    BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
    dataPlanePlugin.initialize(batfish);
    _thrown.expect(BdpOscillationException.class);
    dataPlanePlugin.computeDataPlane(false);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 18 with Batfish

use of org.batfish.main.Batfish in project batfish by batfish.

the class BdpDataPlanePluginTest method testIbgpRejectOwnAs.

@Test
public void testIbgpRejectOwnAs() throws IOException {
    String testrigName = "ibgp-reject-own-as";
    List<String> configurationNames = ImmutableList.of("r1", "r2a", "r2b");
    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> r2aRoutes = routes.get("r2a").get(DEFAULT_VRF_NAME);
    SortedSet<AbstractRoute> r2bRoutes = routes.get("r2b").get(DEFAULT_VRF_NAME);
    Set<Prefix> r2aPrefixes = r2aRoutes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
    Set<Prefix> r2bPrefixes = r2bRoutes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
    Prefix r1Loopback0Prefix = Prefix.parse("1.0.0.1/32");
    Prefix r1Loopback1Prefix = Prefix.parse("1.0.0.2/32");
    assertTrue(r2aPrefixes.contains(r1Loopback0Prefix));
    assertTrue(r2aPrefixes.contains(r1Loopback1Prefix));
    /*
     * 1.0.0.2/32 should be accepted r2b as a normal iBGP route forwarded from r1.
     */
    assertTrue(r2bPrefixes.contains(r1Loopback1Prefix));
    /*
     * 1.0.0.1/32 should be rejected by r2b since it already contains AS#2 in its AS-path due to
     * r2a prepending 2 in the matching route-map clause.
     */
    assertFalse(r2bPrefixes.contains(r1Loopback0Prefix));
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Prefix(org.batfish.datamodel.Prefix) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 19 with Batfish

use of org.batfish.main.Batfish in project batfish by batfish.

the class RipAndBgpTest method testOutputRoutes.

@Test
public void testOutputRoutes() throws IOException {
    String testrigResourcePrefix = TESTRIGS_PREFIX + "rip";
    Set<String> configurations = ImmutableSet.of("r1", "r2", "r3");
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(testrigResourcePrefix, configurations).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(Configuration.DEFAULT_VRF_NAME);
    SortedSet<AbstractRoute> r2Routes = routes.get("r2").get(Configuration.DEFAULT_VRF_NAME);
    SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(Configuration.DEFAULT_VRF_NAME);
    Set<Prefix> r1Prefixes = r1Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
    Set<Prefix> r2Prefixes = r2Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
    Set<Prefix> r3Prefixes = r3Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
    Prefix prefix1 = Prefix.parse("1.0.0.0/8");
    Prefix prefix2 = Prefix.parse("2.0.0.0/8");
    Prefix prefix3 = Prefix.parse("3.0.0.0/8");
    assertThat(r1Prefixes, containsInAnyOrder(prefix1, prefix2, prefix3));
    assertThat(r2Prefixes, containsInAnyOrder(prefix1, prefix2, prefix3));
    assertThat(r3Prefixes, containsInAnyOrder(prefix1, prefix3));
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) SortedMap(java.util.SortedMap) Prefix(org.batfish.datamodel.Prefix) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 20 with Batfish

use of org.batfish.main.Batfish in project batfish by batfish.

the class CiscoGrammarTest method testBgpLocalAs.

@Test
public void testBgpLocalAs() throws IOException {
    String testrigName = "bgp-local-as";
    List<String> configurationNames = ImmutableList.of("r1", "r2");
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    Map<Ip, Set<String>> ipOwners = CommonUtil.computeIpOwners(configurations, true);
    CommonUtil.initRemoteBgpNeighbors(configurations, ipOwners);
    Configuration r1 = configurations.get("r1");
    Configuration r2 = configurations.get("r2");
    assertThat(r1.getDefaultVrf().getBgpProcess().getNeighbors().get(Prefix.parse("1.2.0.2/32")).getRemoteBgpNeighbor(), is(notNullValue()));
    assertThat(r2.getDefaultVrf().getBgpProcess().getNeighbors().get(Prefix.parse("1.2.0.1/32")).getRemoteBgpNeighbor(), is(notNullValue()));
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) Configuration(org.batfish.datamodel.Configuration) Ip(org.batfish.datamodel.Ip) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Aggregations

Batfish (org.batfish.main.Batfish)32 Test (org.junit.Test)25 Configuration (org.batfish.datamodel.Configuration)20 Prefix (org.batfish.datamodel.Prefix)10 SortedMap (java.util.SortedMap)9 AbstractRoute (org.batfish.datamodel.AbstractRoute)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 SortedSet (java.util.SortedSet)7 Interface (org.batfish.datamodel.Interface)7 Ip (org.batfish.datamodel.Ip)7 TemporaryFolder (org.junit.rules.TemporaryFolder)7 Set (java.util.Set)6 MultipathEquivalentAsPathMatchMode (org.batfish.datamodel.MultipathEquivalentAsPathMatchMode)6 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)5 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)5 Vrf (org.batfish.datamodel.Vrf)5 ImmutableList (com.google.common.collect.ImmutableList)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 List (java.util.List)4