Search in sources :

Example 6 with Batfish

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

the class CiscoGrammarTest method testBgpMultipathRelax.

@Test
public void testBgpMultipathRelax() throws IOException {
    String testrigName = "bgp-multipath-relax";
    List<String> configurationNames = ImmutableList.of("arista_disabled", "arista_enabled", "nxos_disabled", "nxos_enabled");
    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);
    MultipathEquivalentAsPathMatchMode aristaDisabled = configurations.get("arista_disabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
    MultipathEquivalentAsPathMatchMode aristaEnabled = configurations.get("arista_enabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
    MultipathEquivalentAsPathMatchMode nxosDisabled = configurations.get("nxos_disabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
    MultipathEquivalentAsPathMatchMode nxosEnabled = configurations.get("nxos_enabled").getDefaultVrf().getBgpProcess().getMultipathEquivalentAsPathMatchMode();
    assertThat(aristaDisabled, equalTo(MultipathEquivalentAsPathMatchMode.EXACT_PATH));
    assertThat(aristaEnabled, equalTo(MultipathEquivalentAsPathMatchMode.PATH_LENGTH));
    assertThat(nxosDisabled, equalTo(MultipathEquivalentAsPathMatchMode.EXACT_PATH));
    assertThat(nxosEnabled, equalTo(MultipathEquivalentAsPathMatchMode.PATH_LENGTH));
}
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) MultipathEquivalentAsPathMatchMode(org.batfish.datamodel.MultipathEquivalentAsPathMatchMode) Test(org.junit.Test)

Example 7 with Batfish

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

the class CiscoGrammarTest method testParsingRecoveryNoInfiniteLoopDuringAdaptivePredictionAtEof.

@Test
public void testParsingRecoveryNoInfiniteLoopDuringAdaptivePredictionAtEof() throws IOException {
    String testrigName = "parsing-recovery";
    String hostname = "ios-blankish-file";
    List<String> configurationNames = ImmutableList.of(hostname);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    batfish.getSettings().setDisableUnrecognized(false);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    /* Hostname is unknown, but a file should be generated nonetheless */
    assertThat(configurations.entrySet(), hasSize(1));
}
Also used : Configuration(org.batfish.datamodel.Configuration) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 8 with Batfish

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

the class CiscoGrammarTest method testIpsecVpnIos.

@Test
public void testIpsecVpnIos() throws IOException {
    String testrigName = "ipsec-vpn-ios";
    List<String> configurationNames = ImmutableList.of("r1", "r2", "r3");
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    assertThat(configurations.values().stream().mapToLong(c -> c.getIpsecVpns().values().size()).sum(), equalTo(6L));
    configurations.values().stream().flatMap(c -> c.getIpsecVpns().values().stream()).forEach(iv -> assertThat(iv.getRemoteIpsecVpn(), not(nullValue())));
    /* Two tunnels should not be established because of a password mismatch between r1 and r3 */
    assertThat(configurations.values().stream().flatMap(c -> c.getInterfaces().values().stream()).filter(i -> i.getInterfaceType().equals(InterfaceType.TUNNEL) && i.getActive()).count(), equalTo(4L));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) OspfAreaSummaryMatchers.isAdvertised(org.batfish.datamodel.matchers.OspfAreaSummaryMatchers.isAdvertised) Matchers.hasKey(org.hamcrest.Matchers.hasKey) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Interface(org.batfish.datamodel.Interface) Assert.assertThat(org.junit.Assert.assertThat) InterfaceMatchers.hasMtu(org.batfish.datamodel.matchers.InterfaceMatchers.hasMtu) OspfProcess(org.batfish.datamodel.OspfProcess) OspfProcessMatchers.hasAreas(org.batfish.datamodel.matchers.OspfProcessMatchers.hasAreas) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) WellKnownCommunity(org.batfish.common.WellKnownCommunity) OspfProcess.getReferenceOspfBandwidth(org.batfish.representation.cisco.OspfProcess.getReferenceOspfBandwidth) InterfaceMatchers.hasVrf(org.batfish.datamodel.matchers.InterfaceMatchers.hasVrf) Vrf(org.batfish.datamodel.Vrf) OspfArea(org.batfish.datamodel.OspfArea) InterfaceMatchers.hasDeclaredNames(org.batfish.datamodel.matchers.InterfaceMatchers.hasDeclaredNames) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) InterfaceMatchers.isProxyArp(org.batfish.datamodel.matchers.InterfaceMatchers.isProxyArp) Collection(java.util.Collection) InterfaceMatchers.isOspfPointToPoint(org.batfish.datamodel.matchers.InterfaceMatchers.isOspfPointToPoint) Set(java.util.Set) LoggingMatchers.isOn(org.batfish.datamodel.vendor_family.cisco.LoggingMatchers.isOn) OspfAreaMatchers.hasSummary(org.batfish.datamodel.matchers.OspfAreaMatchers.hasSummary) Collectors(java.util.stream.Collectors) AsPath(org.batfish.datamodel.AsPath) OspfProcessMatchers.hasArea(org.batfish.datamodel.matchers.OspfProcessMatchers.hasArea) List(java.util.List) MultipathEquivalentAsPathMatchMode(org.batfish.datamodel.MultipathEquivalentAsPathMatchMode) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ConfigurationMatchers.hasVendorFamily(org.batfish.datamodel.matchers.ConfigurationMatchers.hasVendorFamily) OspfAreaSummaryMatchers.hasMetric(org.batfish.datamodel.matchers.OspfAreaSummaryMatchers.hasMetric) SortedMap(java.util.SortedMap) Ip(org.batfish.datamodel.Ip) BatfishTestUtils(org.batfish.main.BatfishTestUtils) BdpDataPlanePlugin(org.batfish.bdp.BdpDataPlanePlugin) InterfaceMatchers.isOspfPassive(org.batfish.datamodel.matchers.InterfaceMatchers.isOspfPassive) CommonUtil(org.batfish.common.util.CommonUtil) CoreMatchers.not(org.hamcrest.CoreMatchers.not) InterfaceMatchers.hasOspfArea(org.batfish.datamodel.matchers.InterfaceMatchers.hasOspfArea) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) CommunityList(org.batfish.datamodel.CommunityList) ImmutableList(com.google.common.collect.ImmutableList) AbstractRoute(org.batfish.datamodel.AbstractRoute) CiscoFamilyMatchers.hasLogging(org.batfish.datamodel.vendor_family.cisco.CiscoFamilyMatchers.hasLogging) Configuration(org.batfish.datamodel.Configuration) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Batfish(org.batfish.main.Batfish) Matchers.isIn(org.hamcrest.Matchers.isIn) TestrigText(org.batfish.main.TestrigText) ExpectedException(org.junit.rules.ExpectedException) VrfMatchers.hasOspfProcess(org.batfish.datamodel.matchers.VrfMatchers.hasOspfProcess) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Assert.assertTrue(org.junit.Assert.assertTrue) OspfAreaMatchers(org.batfish.datamodel.matchers.OspfAreaMatchers) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) Test(org.junit.Test) ConfigurationMatchers.hasDefaultVrf(org.batfish.datamodel.matchers.ConfigurationMatchers.hasDefaultVrf) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Rule(org.junit.Rule) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ConfigurationMatchers.hasInterfaces(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterfaces) VendorFamilyMatchers.hasCisco(org.batfish.datamodel.vendor_family.VendorFamilyMatchers.hasCisco) ConfigurationMatchers.hasInterface(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterface) ConfigurationMatchers.hasVrfs(org.batfish.datamodel.matchers.ConfigurationMatchers.hasVrfs) TemporaryFolder(org.junit.rules.TemporaryFolder) Prefix(org.batfish.datamodel.Prefix) Configuration(org.batfish.datamodel.Configuration) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 9 with Batfish

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

the class CiscoGrammarTest method testParsingRecovery.

@Test
public void testParsingRecovery() throws IOException {
    String testrigName = "parsing-recovery";
    String hostname = "ios-recovery";
    List<String> configurationNames = ImmutableList.of(hostname);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    batfish.getSettings().setDisableUnrecognized(false);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    Configuration iosRecovery = configurations.get(hostname);
    Map<String, Interface> iosRecoveryInterfaces = iosRecovery.getInterfaces();
    Set<String> iosRecoveryInterfaceNames = iosRecoveryInterfaces.keySet();
    Set<InterfaceAddress> l3Prefixes = iosRecoveryInterfaces.get("Loopback3").getAllAddresses();
    Set<InterfaceAddress> l4Prefixes = iosRecoveryInterfaces.get("Loopback4").getAllAddresses();
    assertThat("Loopback0", isIn(iosRecoveryInterfaceNames));
    assertThat("Loopback1", isIn(iosRecoveryInterfaceNames));
    assertThat("Loopback2", not(isIn(iosRecoveryInterfaceNames)));
    assertThat("Loopback3", isIn(iosRecoveryInterfaceNames));
    assertThat(new InterfaceAddress("10.0.0.1/32"), not(isIn(l3Prefixes)));
    assertThat(new InterfaceAddress("10.0.0.2/32"), isIn(l3Prefixes));
    assertThat("Loopback4", isIn(iosRecoveryInterfaceNames));
    assertThat(new InterfaceAddress("10.0.0.3/32"), not(isIn(l4Prefixes)));
    assertThat(new InterfaceAddress("10.0.0.4/32"), isIn(l4Prefixes));
}
Also used : Configuration(org.batfish.datamodel.Configuration) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Batfish(org.batfish.main.Batfish) Interface(org.batfish.datamodel.Interface) ConfigurationMatchers.hasInterface(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterface) Test(org.junit.Test)

Example 10 with Batfish

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

the class CiscoGrammarTest method testOspfMaxMetric.

@Test
public void testOspfMaxMetric() throws IOException {
    String testrigName = "ospf-max-metric";
    String iosMaxMetricName = "ios-max-metric";
    String iosMaxMetricCustomName = "ios-max-metric-custom";
    String iosMaxMetricOnStartupName = "ios-max-metric-on-startup";
    List<String> configurationNames = ImmutableList.of(iosMaxMetricName, iosMaxMetricCustomName, iosMaxMetricOnStartupName);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    Configuration iosMaxMetric = configurations.get(iosMaxMetricName);
    Configuration iosMaxMetricCustom = configurations.get(iosMaxMetricCustomName);
    Configuration iosMaxMetricOnStartup = configurations.get(iosMaxMetricOnStartupName);
    OspfProcess proc = iosMaxMetric.getDefaultVrf().getOspfProcess();
    OspfProcess procCustom = iosMaxMetricCustom.getDefaultVrf().getOspfProcess();
    OspfProcess procOnStartup = iosMaxMetricOnStartup.getDefaultVrf().getOspfProcess();
    long expectedMaxMetricRouterLsa = org.batfish.representation.cisco.OspfProcess.MAX_METRIC_ROUTER_LSA;
    long expectedMaxMetricStub = org.batfish.representation.cisco.OspfProcess.MAX_METRIC_ROUTER_LSA;
    long expectedMaxMetricExternal = org.batfish.representation.cisco.OspfProcess.DEFAULT_MAX_METRIC_EXTERNAL_LSA;
    long expectedMaxMetricSummary = org.batfish.representation.cisco.OspfProcess.DEFAULT_MAX_METRIC_SUMMARY_LSA;
    long expectedCustomMaxMetricExternal = 12345L;
    long expectedCustomMaxMetricSummary = 23456L;
    assertThat(proc.getMaxMetricTransitLinks(), equalTo(expectedMaxMetricRouterLsa));
    assertThat(proc.getMaxMetricStubNetworks(), equalTo(expectedMaxMetricStub));
    assertThat(proc.getMaxMetricExternalNetworks(), equalTo(expectedMaxMetricExternal));
    assertThat(proc.getMaxMetricSummaryNetworks(), equalTo(expectedMaxMetricSummary));
    assertThat(procCustom.getMaxMetricTransitLinks(), equalTo(expectedMaxMetricRouterLsa));
    assertThat(procCustom.getMaxMetricStubNetworks(), equalTo(expectedMaxMetricStub));
    assertThat(procCustom.getMaxMetricExternalNetworks(), equalTo(expectedCustomMaxMetricExternal));
    assertThat(procCustom.getMaxMetricSummaryNetworks(), equalTo(expectedCustomMaxMetricSummary));
    assertThat(procOnStartup.getMaxMetricTransitLinks(), is(nullValue()));
    assertThat(procOnStartup.getMaxMetricStubNetworks(), is(nullValue()));
    assertThat(procOnStartup.getMaxMetricExternalNetworks(), is(nullValue()));
    assertThat(procOnStartup.getMaxMetricSummaryNetworks(), is(nullValue()));
}
Also used : Configuration(org.batfish.datamodel.Configuration) OspfProcess(org.batfish.datamodel.OspfProcess) VrfMatchers.hasOspfProcess(org.batfish.datamodel.matchers.VrfMatchers.hasOspfProcess) 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