use of org.batfish.datamodel.AsPath in project batfish by batfish.
the class VirtualRouterTest method computeBgpAdvertisementsSTOEbgpAdvertiseInactive.
@Test
public void computeBgpAdvertisementsSTOEbgpAdvertiseInactive() {
RoutingPolicy exportPolicy = _routingPolicyBuilder.setStatements(ImmutableList.of(new SetOrigin(new LiteralOrigin(OriginType.INCOMPLETE, null)), _exitAcceptStatement)).build();
_bgpNeighborBuilder.setRemoteAs(TEST_AS2).setExportPolicy(exportPolicy.getName()).setAdvertiseInactive(true).build();
_testVirtualRouter._bgpBestPathRib.mergeRoute(_bgpRouteBuilder.setNextHopIp(TEST_NEXT_HOP_IP1).setReceivedFromIp(TEST_NEXT_HOP_IP1).setAsPath(AsPath.ofSingletonAsSets(TEST_AS3).getAsSets()).build());
// adding a connected route in main rib
_testVirtualRouter._mainRib.mergeRoute(new ConnectedRoute(TEST_NETWORK, Route.UNSET_NEXT_HOP_INTERFACE));
// checking that the inactive BGP route got advertised along with the active OSPF route
assertThat(_testVirtualRouter.computeBgpAdvertisementsToOutside(_ipOwners), equalTo(2));
// checking that both bgp advertisements have the same network and correct AS Paths
Set<AsPath> asPaths = new HashSet<>();
_testVirtualRouter._sentBgpAdvertisements.stream().forEach(bgpAdvertisement -> {
assertThat(bgpAdvertisement, hasNetwork(TEST_NETWORK));
asPaths.add(bgpAdvertisement.getAsPath());
});
// next Hop IP for the active OSPF route will be the neighbor's local IP
assertThat("AS Paths not valid in BGP advertisements", asPaths, equalTo(ImmutableSet.of(AsPath.ofSingletonAsSets(TEST_AS1, TEST_AS3), AsPath.ofSingletonAsSets(TEST_AS1))));
}
use of org.batfish.datamodel.AsPath 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);
}
Aggregations