use of org.batfish.datamodel.AbstractRoute in project batfish by batfish.
the class BdpEngine method getRoutes.
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> getRoutes(BdpDataPlane dp) {
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routesByHostname = new TreeMap<>();
for (Entry<String, Node> e : dp._nodes.entrySet()) {
String hostname = e.getKey();
Node node = e.getValue();
for (Entry<String, VirtualRouter> e2 : node._virtualRouters.entrySet()) {
String vrfName = e2.getKey();
VirtualRouter vrf = e2.getValue();
for (AbstractRoute route : vrf._mainRib.getRoutes()) {
SortedMap<String, SortedSet<AbstractRoute>> routesByVrf = routesByHostname.computeIfAbsent(hostname, k -> new TreeMap<>());
SortedSet<AbstractRoute> routes = routesByVrf.computeIfAbsent(vrfName, k -> new TreeSet<>());
routes.add(route);
}
}
}
return routesByHostname;
}
use of org.batfish.datamodel.AbstractRoute in project batfish by batfish.
the class BdpDataPlanePluginTest method testIbgpRejectOwnAs.
@Test
public void testIbgpRejectOwnAs() throws IOException {
String testrigName = "ibgp-reject-own-as";
List<String> configurationNames = ImmutableList.of("r1", "r2a", "r2b");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
batfish.computeDataPlane(false);
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
SortedSet<AbstractRoute> r2aRoutes = routes.get("r2a").get(DEFAULT_VRF_NAME);
SortedSet<AbstractRoute> r2bRoutes = routes.get("r2b").get(DEFAULT_VRF_NAME);
Set<Prefix> r2aPrefixes = r2aRoutes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
Set<Prefix> r2bPrefixes = r2bRoutes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
Prefix r1Loopback0Prefix = Prefix.parse("1.0.0.1/32");
Prefix r1Loopback1Prefix = Prefix.parse("1.0.0.2/32");
assertTrue(r2aPrefixes.contains(r1Loopback0Prefix));
assertTrue(r2aPrefixes.contains(r1Loopback1Prefix));
/*
* 1.0.0.2/32 should be accepted r2b as a normal iBGP route forwarded from r1.
*/
assertTrue(r2bPrefixes.contains(r1Loopback1Prefix));
/*
* 1.0.0.1/32 should be rejected by r2b since it already contains AS#2 in its AS-path due to
* r2a prepending 2 in the matching route-map clause.
*/
assertFalse(r2bPrefixes.contains(r1Loopback0Prefix));
}
use of org.batfish.datamodel.AbstractRoute in project batfish by batfish.
the class OspfTest method assertRoute.
private static void assertRoute(SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routesByNode, RoutingProtocol protocol, String hostname, InterfaceAddress address, long expectedCost) {
Prefix prefix = address.getPrefix();
assertThat(routesByNode, hasKey(hostname));
SortedMap<String, SortedSet<AbstractRoute>> routesByVrf = routesByNode.get(hostname);
assertThat(routesByVrf, hasKey(Configuration.DEFAULT_VRF_NAME));
SortedSet<AbstractRoute> routes = routesByVrf.get(Configuration.DEFAULT_VRF_NAME);
assertThat(routes, hasItem(hasPrefix(prefix)));
AbstractRoute route = routes.stream().filter(r -> r.getNetwork().equals(prefix)).findAny().get();
assertThat(route, hasMetric(expectedCost));
assertThat(route, hasProtocol(protocol));
}
use of org.batfish.datamodel.AbstractRoute in project batfish by batfish.
the class RipAndBgpTest method testOutputRoutes.
@Test
public void testOutputRoutes() throws IOException {
String testrigResourcePrefix = TESTRIGS_PREFIX + "rip";
Set<String> configurations = ImmutableSet.of("r1", "r2", "r3");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(testrigResourcePrefix, configurations).build(), _folder);
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
batfish.computeDataPlane(false);
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
SortedSet<AbstractRoute> r1Routes = routes.get("r1").get(Configuration.DEFAULT_VRF_NAME);
SortedSet<AbstractRoute> r2Routes = routes.get("r2").get(Configuration.DEFAULT_VRF_NAME);
SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(Configuration.DEFAULT_VRF_NAME);
Set<Prefix> r1Prefixes = r1Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
Set<Prefix> r2Prefixes = r2Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
Set<Prefix> r3Prefixes = r3Routes.stream().map(AbstractRoute::getNetwork).collect(Collectors.toSet());
Prefix prefix1 = Prefix.parse("1.0.0.0/8");
Prefix prefix2 = Prefix.parse("2.0.0.0/8");
Prefix prefix3 = Prefix.parse("3.0.0.0/8");
assertThat(r1Prefixes, containsInAnyOrder(prefix1, prefix2, prefix3));
assertThat(r2Prefixes, containsInAnyOrder(prefix1, prefix2, prefix3));
assertThat(r3Prefixes, containsInAnyOrder(prefix1, prefix3));
}
use of org.batfish.datamodel.AbstractRoute in project batfish by batfish.
the class RouteReflectionTest method assertIbgpRoute.
private static void assertIbgpRoute(SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routesByNode, String hostname, Prefix prefix) {
assertThat(routesByNode, hasKey(hostname));
SortedMap<String, SortedSet<AbstractRoute>> routesByVrf = routesByNode.get(hostname);
assertThat(routesByVrf, hasKey(Configuration.DEFAULT_VRF_NAME));
SortedSet<AbstractRoute> routes = routesByVrf.get(Configuration.DEFAULT_VRF_NAME);
assertThat(routes, hasItem(hasPrefix(prefix)));
AbstractRoute route = routes.stream().filter(r -> r.getNetwork().equals(prefix)).findAny().get();
assertThat(route, hasProtocol(RoutingProtocol.IBGP));
}
Aggregations