use of org.batfish.datamodel.AbstractRoute 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.datamodel.AbstractRoute in project batfish by batfish.
the class BatfishCompressionTest method testCompressionFibs_compressibleNetwork.
/**
* Test the following invariant: if a FIB appears on concrete router “r”, then a corresponding
* abstract FIB appears on one of these representatives. For example, if there is a concrete FIB
* from C to D, then there should be an abstract FIB from A to B, where A is in representatives(C)
* and B is in representatives(D).
*/
@Test
public void testCompressionFibs_compressibleNetwork() throws IOException {
DataPlane origDataPlane = getDataPlane(compressibleNetwork());
SortedMap<String, Configuration> compressedConfigs = compressNetwork(compressibleNetwork(), new HeaderSpace());
DataPlane compressedDataPlane = getDataPlane(compressedConfigs);
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> origRibs = origDataPlane.getRibs();
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> compressedRibs = compressedDataPlane.getRibs();
/* Compression removed a node */
assertThat(compressedConfigs.entrySet(), hasSize(2));
compressedConfigs.values().forEach(BatfishCompressionTest::assertIsCompressedConfig);
compressedRibs.forEach((hostname, compressedRibsByVrf) -> compressedRibsByVrf.forEach((vrf, compressedRib) -> {
GenericRib<AbstractRoute> origRib = origRibs.get(hostname).get(vrf);
Set<AbstractRoute> origRoutes = origRib.getRoutes();
Set<AbstractRoute> compressedRoutes = compressedRib.getRoutes();
for (AbstractRoute route : compressedRoutes) {
/* Every compressed route should appear in original RIB */
assertThat(origRoutes, hasItem(route));
}
}));
}
Aggregations