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