Search in sources :

Example 21 with Batfish

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

the class CiscoGrammarTest method testNxosOspfNonDefaultVrf.

@Test
public void testNxosOspfNonDefaultVrf() throws IOException {
    String testrigName = "nxos-ospf";
    String hostname = "nxos-ospf-iface-in-vrf";
    String ifaceName = "Ethernet1";
    String vrfName = "OTHER-VRF";
    long areaNum = 1L;
    List<String> configurationNames = ImmutableList.of(hostname);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    /* Ensure bidirectional references between OSPF area and interface */
    assertThat(configurations, hasKey(hostname));
    Configuration c = configurations.get(hostname);
    assertThat(c, hasVrfs(hasKey(vrfName)));
    Vrf vrf = c.getVrfs().get(vrfName);
    assertThat(vrf, hasOspfProcess(hasAreas(hasKey(areaNum))));
    OspfArea area = vrf.getOspfProcess().getAreas().get(areaNum);
    assertThat(area, OspfAreaMatchers.hasInterfaces(hasItem(ifaceName)));
    assertThat(c, hasInterface(ifaceName, hasVrf(sameInstance(vrf))));
    assertThat(c, hasInterface(ifaceName, hasOspfArea(sameInstance(area))));
    assertThat(c, hasInterface(ifaceName, isOspfPassive(equalTo(false))));
    assertThat(c, hasInterface(ifaceName, isOspfPointToPoint()));
}
Also used : OspfArea(org.batfish.datamodel.OspfArea) InterfaceMatchers.hasOspfArea(org.batfish.datamodel.matchers.InterfaceMatchers.hasOspfArea) Configuration(org.batfish.datamodel.Configuration) InterfaceMatchers.hasVrf(org.batfish.datamodel.matchers.InterfaceMatchers.hasVrf) Vrf(org.batfish.datamodel.Vrf) ConfigurationMatchers.hasDefaultVrf(org.batfish.datamodel.matchers.ConfigurationMatchers.hasDefaultVrf) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 22 with Batfish

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

the class CiscoGrammarTest method testOspfPointToPoint.

@Test
public void testOspfPointToPoint() throws IOException {
    String testrigName = "ospf-point-to-point";
    String iosOspfPointToPoint = "ios-ospf-point-to-point";
    List<String> configurationNames = ImmutableList.of(iosOspfPointToPoint);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    Configuration iosMaxMetric = configurations.get(iosOspfPointToPoint);
    Interface e0Sub0 = iosMaxMetric.getInterfaces().get("Ethernet0/0");
    Interface e0Sub1 = iosMaxMetric.getInterfaces().get("Ethernet0/1");
    assertTrue(e0Sub0.getOspfPointToPoint());
    assertFalse(e0Sub1.getOspfPointToPoint());
}
Also used : Configuration(org.batfish.datamodel.Configuration) Batfish(org.batfish.main.Batfish) Interface(org.batfish.datamodel.Interface) ConfigurationMatchers.hasInterface(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterface) Test(org.junit.Test)

Example 23 with Batfish

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

the class CiscoGrammarTest method testParsingUnrecognizedInterfaceName.

@Test
public void testParsingUnrecognizedInterfaceName() throws IOException {
    String testrigName = "parsing-recovery";
    String hostname = "ios-bad-interface-name";
    List<String> configurationNames = ImmutableList.of(hostname);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    /* Parser should not crash, and configuration with hostname from file should be generated */
    assertThat(configurations, hasKey(hostname));
}
Also used : Configuration(org.batfish.datamodel.Configuration) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 24 with Batfish

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

the class CiscoGrammarTest method testBgpRemovePrivateAs.

@Test
public void testBgpRemovePrivateAs() throws IOException {
    String testrigName = "bgp-remove-private-as";
    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();
    Map<Ip, Set<String>> ipOwners = CommonUtil.computeIpOwners(configurations, true);
    CommonUtil.initRemoteBgpNeighbors(configurations, ipOwners);
    BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
    dataPlanePlugin.initialize(batfish);
    // compute and cache the dataPlane
    batfish.computeDataPlane(false);
    // Check that 1.1.1.1/32 appears on r3
    SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
    SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(Configuration.DEFAULT_VRF_NAME);
    Set<Prefix> r3Prefixes = r3Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
    Prefix r1Loopback = Prefix.parse("1.1.1.1/32");
    assertTrue(r3Prefixes.contains(r1Loopback));
    // check that private AS is present in path in received 1.1.1.1/32 advert on r2
    batfish.initBgpAdvertisements(configurations);
    Configuration r2 = configurations.get("r2");
    boolean r2HasPrivate = r2.getReceivedEbgpAdvertisements().stream().filter(a -> a.getNetwork().equals(r1Loopback)).toArray(BgpAdvertisement[]::new)[0].getAsPath().getAsSets().stream().flatMap(Collection::stream).anyMatch(AsPath::isPrivateAs);
    assertTrue(r2HasPrivate);
    // check that private AS is absent from path in received 1.1.1.1/32 advert on r3
    Configuration r3 = configurations.get("r3");
    boolean r3HasPrivate = r3.getReceivedEbgpAdvertisements().stream().filter(a -> a.getNetwork().equals(r1Loopback)).toArray(BgpAdvertisement[]::new)[0].getAsPath().getAsSets().stream().flatMap(Collection::stream).anyMatch(AsPath::isPrivateAs);
    assertFalse(r3HasPrivate);
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) 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) SortedSet(java.util.SortedSet) Set(java.util.Set) Configuration(org.batfish.datamodel.Configuration) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) AsPath(org.batfish.datamodel.AsPath) SortedMap(java.util.SortedMap) BdpDataPlanePlugin(org.batfish.bdp.BdpDataPlanePlugin) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 25 with Batfish

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

the class CiscoGrammarTest method testCommunityListConversion.

@Test
public void testCommunityListConversion() throws IOException {
    String testrigName = "community-list-conversion";
    String iosName = "ios";
    String nxosName = "nxos";
    String eosName = "eos";
    List<String> configurationNames = ImmutableList.of(iosName, nxosName, eosName);
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    Configuration iosCommunityListConfig = configurations.get(iosName);
    SortedMap<String, CommunityList> iosCommunityLists = iosCommunityListConfig.getCommunityLists();
    Configuration eosCommunityListConfig = configurations.get(eosName);
    SortedMap<String, CommunityList> eosCommunityLists = eosCommunityListConfig.getCommunityLists();
    Configuration nxosCommunityListConfig = configurations.get(nxosName);
    SortedMap<String, CommunityList> nxosCommunityLists = nxosCommunityListConfig.getCommunityLists();
    String iosRegexImpliedStd = getCLRegex(iosCommunityLists, "40");
    String iosRegexImpliedExp = getCLRegex(iosCommunityLists, "400");
    String iosRegexStd = getCLRegex(iosCommunityLists, "std_community");
    String iosRegexExp = getCLRegex(iosCommunityLists, "exp_community");
    String iosRegexStdAsnn = getCLRegex(iosCommunityLists, "std_as_nn");
    String iosRegexExpAsnn = getCLRegex(iosCommunityLists, "exp_as_nn");
    String iosRegexStdGshut = getCLRegex(iosCommunityLists, "std_gshut");
    String iosRegexExpGshut = getCLRegex(iosCommunityLists, "exp_gshut");
    String iosRegexStdInternet = getCLRegex(iosCommunityLists, "std_internet");
    String iosRegexExpInternet = getCLRegex(iosCommunityLists, "exp_internet");
    String iosRegexStdLocalAs = getCLRegex(iosCommunityLists, "std_local_AS");
    String iosRegexExpLocalAs = getCLRegex(iosCommunityLists, "exp_local_AS");
    String iosRegexStdNoAdv = getCLRegex(iosCommunityLists, "std_no_advertise");
    String iosRegexExpNoAdv = getCLRegex(iosCommunityLists, "exp_no_advertise");
    String iosRegexStdNoExport = getCLRegex(iosCommunityLists, "std_no_export");
    String iosRegexExpNoExport = getCLRegex(iosCommunityLists, "exp_no_export");
    String eosRegexStd = getCLRegex(eosCommunityLists, "eos_std");
    String eosRegexExp = getCLRegex(eosCommunityLists, "eos_exp");
    String eosRegexStdGshut = getCLRegex(eosCommunityLists, "eos_std_gshut");
    String eosRegexStdInternet = getCLRegex(eosCommunityLists, "eos_std_internet");
    String eosRegexStdLocalAs = getCLRegex(eosCommunityLists, "eos_std_local_AS");
    String eosRegexStdNoAdv = getCLRegex(eosCommunityLists, "eos_std_no_adv");
    String eosRegexStdNoExport = getCLRegex(eosCommunityLists, "eos_std_no_export");
    String eosRegexStdMulti = getCLRegex(eosCommunityLists, "eos_std_multi");
    String eosRegexExpMulti = getCLRegex(eosCommunityLists, "eos_exp_multi");
    String nxosRegexStd = getCLRegex(nxosCommunityLists, "nxos_std");
    String nxosRegexExp = getCLRegex(nxosCommunityLists, "nxos_exp");
    String nxosRegexStdInternet = getCLRegex(nxosCommunityLists, "nxos_std_internet");
    String nxosRegexStdLocalAs = getCLRegex(nxosCommunityLists, "nxos_std_local_AS");
    String nxosRegexStdNoAdv = getCLRegex(nxosCommunityLists, "nxos_std_no_adv");
    String nxosRegexStdNoExport = getCLRegex(nxosCommunityLists, "nxos_std_no_export");
    String nxosRegexStdMulti = getCLRegex(nxosCommunityLists, "nxos_std_multi");
    String nxosRegexExpMulti = getCLRegex(nxosCommunityLists, "nxos_exp_multi");
    // Check well known community regexes are generated properly
    String regexInternet = "^" + CommonUtil.longToCommunity(WellKnownCommunity.INTERNET.getValue()) + "$";
    String regexNoAdv = "^" + CommonUtil.longToCommunity(WellKnownCommunity.NO_ADVERTISE.getValue()) + "$";
    String regexNoExport = "^" + CommonUtil.longToCommunity(WellKnownCommunity.NO_EXPORT.getValue()) + "$";
    String regexGshut = "^" + CommonUtil.longToCommunity(WellKnownCommunity.GSHUT.getValue()) + "$";
    String regexLocalAs = "^" + CommonUtil.longToCommunity(WellKnownCommunity.LOCAL_AS.getValue()) + "$";
    assertThat(iosRegexStdInternet, equalTo(regexInternet));
    assertThat(iosRegexStdNoAdv, equalTo(regexNoAdv));
    assertThat(iosRegexStdNoExport, equalTo(regexNoExport));
    assertThat(iosRegexStdGshut, equalTo(regexGshut));
    assertThat(iosRegexStdLocalAs, equalTo(regexLocalAs));
    assertThat(eosRegexStdInternet, equalTo(regexInternet));
    assertThat(eosRegexStdNoAdv, equalTo(regexNoAdv));
    assertThat(eosRegexStdNoExport, equalTo(regexNoExport));
    assertThat(eosRegexStdGshut, equalTo(regexGshut));
    assertThat(eosRegexStdLocalAs, equalTo(regexLocalAs));
    // NX-OS does not support gshut
    assertThat(nxosRegexStdInternet, equalTo(regexInternet));
    assertThat(nxosRegexStdNoAdv, equalTo(regexNoAdv));
    assertThat(nxosRegexStdNoExport, equalTo(regexNoExport));
    assertThat(nxosRegexStdLocalAs, equalTo(regexLocalAs));
    // Confirm for the same literal communities, standard and expanded regexs are different
    assertThat(iosRegexImpliedStd, not(equalTo(iosRegexImpliedExp)));
    assertThat(iosRegexStd, not(equalTo(iosRegexExp)));
    assertThat(iosRegexStdAsnn, not(equalTo(iosRegexExpAsnn)));
    assertThat(iosRegexStdInternet, not(equalTo(iosRegexExpInternet)));
    assertThat(iosRegexStdNoAdv, not(equalTo(iosRegexExpNoAdv)));
    assertThat(iosRegexStdNoExport, not(equalTo(iosRegexExpNoExport)));
    assertThat(iosRegexStdGshut, not(equalTo(iosRegexExpGshut)));
    assertThat(iosRegexStdLocalAs, not(equalTo(iosRegexExpLocalAs)));
    assertThat(eosRegexStd, not(equalTo(eosRegexExp)));
    assertThat(eosRegexStdMulti, not(equalTo(eosRegexExpMulti)));
    assertThat(nxosRegexStd, not(equalTo(nxosRegexExp)));
    assertThat(nxosRegexStdMulti, not(equalTo(nxosRegexExpMulti)));
}
Also used : Configuration(org.batfish.datamodel.Configuration) CommunityList(org.batfish.datamodel.CommunityList) 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