use of org.batfish.datamodel.GenericRib in project batfish by batfish.
the class BatfishCompressionTest method testCompressionFibs_diamondNetwork.
/**
* 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_diamondNetwork() throws IOException {
IpAccessListLine line = new IpAccessListLine();
line.setDstIps(ImmutableList.of(new IpWildcard(Prefix.parse("4.4.4.4/32"))));
SortedMap<String, Configuration> origConfigs = diamondNetwork();
DataPlane origDataPlane = getDataPlane(origConfigs);
Map<String, Map<String, Fib>> origFibs = origDataPlane.getFibs();
Topology origTopology = new Topology(origDataPlane.getTopologyEdges());
/* Node A should have a route with C as a next hop. */
assertThat(origFibs, hasEntry(equalTo("A"), hasEntry(equalTo(Configuration.DEFAULT_VRF_NAME), hasNextHopInterfaces(hasValue(hasKey(withNode("A", isNeighborOfNode(origTopology, "C"))))))));
// compress a new copy since it will get mutated.
SortedMap<String, Configuration> compressedConfigs = new TreeMap<>(compressNetwork(diamondNetwork(), line));
DataPlane compressedDataPlane = getDataPlane(compressedConfigs);
compressedConfigs.values().forEach(BatfishCompressionTest::assertIsCompressedConfig);
assertThat(compressedConfigs.values(), hasSize(3));
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> origRibs = origDataPlane.getRibs();
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> compressedRibs = compressedDataPlane.getRibs();
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));
}
}));
/* Compression removed B or C entirely (but not both) */
assertThat(compressedRibs, either(not(hasKey("B"))).or(not(hasKey("C"))));
assertThat(compressedRibs, either(hasKey("B")).or(hasKey("C")));
String remains = compressedConfigs.containsKey("B") ? "B" : "C";
/* The remaining node is unchanged. */
assertThat(origRibs.get(remains).get(Configuration.DEFAULT_VRF_NAME).getRoutes(), equalTo(compressedRibs.get(remains).get(Configuration.DEFAULT_VRF_NAME).getRoutes()));
}
use of org.batfish.datamodel.GenericRib in project batfish by batfish.
the class BatfishCompressionTest method testCompressionFibs_simpleNetwork.
/**
* Test that compression doesn't change the fibs for this network.
*/
@Test
public void testCompressionFibs_simpleNetwork() throws IOException {
DataPlane origDataPlane = getDataPlane(simpleNetwork());
SortedMap<String, Configuration> compressedConfigs = compressNetwork(simpleNetwork(), new HeaderSpace());
DataPlane compressedDataPlane = getDataPlane(compressedConfigs);
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> origRibs = origDataPlane.getRibs();
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> compressedRibs = compressedDataPlane.getRibs();
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));
}
}));
compressedConfigs.values().forEach(BatfishCompressionTest::assertIsCompressedConfig);
/* No nodes should be missing */
assertThat(origRibs.keySet(), equalTo(compressedRibs.keySet()));
}
use of org.batfish.datamodel.GenericRib 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