Search in sources :

Example 16 with BgpAdvertisement

use of org.batfish.datamodel.BgpAdvertisement 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);
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) OspfAreaSummaryMatchers.isAdvertised(org.batfish.datamodel.matchers.OspfAreaSummaryMatchers.isAdvertised) Matchers.hasKey(org.hamcrest.Matchers.hasKey) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Interface(org.batfish.datamodel.Interface) Assert.assertThat(org.junit.Assert.assertThat) InterfaceMatchers.hasMtu(org.batfish.datamodel.matchers.InterfaceMatchers.hasMtu) OspfProcess(org.batfish.datamodel.OspfProcess) OspfProcessMatchers.hasAreas(org.batfish.datamodel.matchers.OspfProcessMatchers.hasAreas) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) WellKnownCommunity(org.batfish.common.WellKnownCommunity) OspfProcess.getReferenceOspfBandwidth(org.batfish.representation.cisco.OspfProcess.getReferenceOspfBandwidth) InterfaceMatchers.hasVrf(org.batfish.datamodel.matchers.InterfaceMatchers.hasVrf) Vrf(org.batfish.datamodel.Vrf) OspfArea(org.batfish.datamodel.OspfArea) InterfaceMatchers.hasDeclaredNames(org.batfish.datamodel.matchers.InterfaceMatchers.hasDeclaredNames) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) InterfaceMatchers.isProxyArp(org.batfish.datamodel.matchers.InterfaceMatchers.isProxyArp) Collection(java.util.Collection) InterfaceMatchers.isOspfPointToPoint(org.batfish.datamodel.matchers.InterfaceMatchers.isOspfPointToPoint) Set(java.util.Set) LoggingMatchers.isOn(org.batfish.datamodel.vendor_family.cisco.LoggingMatchers.isOn) OspfAreaMatchers.hasSummary(org.batfish.datamodel.matchers.OspfAreaMatchers.hasSummary) Collectors(java.util.stream.Collectors) AsPath(org.batfish.datamodel.AsPath) OspfProcessMatchers.hasArea(org.batfish.datamodel.matchers.OspfProcessMatchers.hasArea) List(java.util.List) MultipathEquivalentAsPathMatchMode(org.batfish.datamodel.MultipathEquivalentAsPathMatchMode) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ConfigurationMatchers.hasVendorFamily(org.batfish.datamodel.matchers.ConfigurationMatchers.hasVendorFamily) OspfAreaSummaryMatchers.hasMetric(org.batfish.datamodel.matchers.OspfAreaSummaryMatchers.hasMetric) SortedMap(java.util.SortedMap) Ip(org.batfish.datamodel.Ip) BatfishTestUtils(org.batfish.main.BatfishTestUtils) BdpDataPlanePlugin(org.batfish.bdp.BdpDataPlanePlugin) InterfaceMatchers.isOspfPassive(org.batfish.datamodel.matchers.InterfaceMatchers.isOspfPassive) CommonUtil(org.batfish.common.util.CommonUtil) CoreMatchers.not(org.hamcrest.CoreMatchers.not) InterfaceMatchers.hasOspfArea(org.batfish.datamodel.matchers.InterfaceMatchers.hasOspfArea) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) CommunityList(org.batfish.datamodel.CommunityList) ImmutableList(com.google.common.collect.ImmutableList) AbstractRoute(org.batfish.datamodel.AbstractRoute) CiscoFamilyMatchers.hasLogging(org.batfish.datamodel.vendor_family.cisco.CiscoFamilyMatchers.hasLogging) Configuration(org.batfish.datamodel.Configuration) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Batfish(org.batfish.main.Batfish) Matchers.isIn(org.hamcrest.Matchers.isIn) TestrigText(org.batfish.main.TestrigText) ExpectedException(org.junit.rules.ExpectedException) VrfMatchers.hasOspfProcess(org.batfish.datamodel.matchers.VrfMatchers.hasOspfProcess) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Assert.assertTrue(org.junit.Assert.assertTrue) OspfAreaMatchers(org.batfish.datamodel.matchers.OspfAreaMatchers) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) Test(org.junit.Test) ConfigurationMatchers.hasDefaultVrf(org.batfish.datamodel.matchers.ConfigurationMatchers.hasDefaultVrf) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Rule(org.junit.Rule) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ConfigurationMatchers.hasInterfaces(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterfaces) VendorFamilyMatchers.hasCisco(org.batfish.datamodel.vendor_family.VendorFamilyMatchers.hasCisco) ConfigurationMatchers.hasInterface(org.batfish.datamodel.matchers.ConfigurationMatchers.hasInterface) ConfigurationMatchers.hasVrfs(org.batfish.datamodel.matchers.ConfigurationMatchers.hasVrfs) TemporaryFolder(org.junit.rules.TemporaryFolder) Prefix(org.batfish.datamodel.Prefix) SortedSet(java.util.SortedSet) Set(java.util.Set) Configuration(org.batfish.datamodel.Configuration) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) AsPath(org.batfish.datamodel.AsPath) SortedMap(java.util.SortedMap) BdpDataPlanePlugin(org.batfish.bdp.BdpDataPlanePlugin) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Aggregations

BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)16 BatfishException (org.batfish.common.BatfishException)7 Ip (org.batfish.datamodel.Ip)7 LinkedHashSet (java.util.LinkedHashSet)6 AsPath (org.batfish.datamodel.AsPath)6 Prefix (org.batfish.datamodel.Prefix)6 TreeSet (java.util.TreeSet)5 AbstractRoute (org.batfish.datamodel.AbstractRoute)5 Configuration (org.batfish.datamodel.Configuration)5 Flow (org.batfish.datamodel.Flow)5 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)5 SortedSet (java.util.SortedSet)4 BgpAdvertisementType (org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType)4 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)4 FlowTrace (org.batfish.datamodel.FlowTrace)4 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3