Search in sources :

Example 11 with AsPath

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))));
}
Also used : ConnectedRoute(org.batfish.datamodel.ConnectedRoute) AsPath(org.batfish.datamodel.AsPath) LiteralOrigin(org.batfish.datamodel.routing_policy.expr.LiteralOrigin) SetOrigin(org.batfish.datamodel.routing_policy.statement.SetOrigin) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 12 with AsPath

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);
}
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

AsPath (org.batfish.datamodel.AsPath)12 Ip (org.batfish.datamodel.Ip)7 BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)6 Prefix (org.batfish.datamodel.Prefix)6 TreeSet (java.util.TreeSet)5 BgpRoute (org.batfish.datamodel.BgpRoute)5 SortedSet (java.util.SortedSet)4 BatfishException (org.batfish.common.BatfishException)4 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)4 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)4 AbstractRoute (org.batfish.datamodel.AbstractRoute)3 BgpAdvertisementType (org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType)3 Configuration (org.batfish.datamodel.Configuration)3 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 OriginType (org.batfish.datamodel.OriginType)2 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)2 Vrf (org.batfish.datamodel.Vrf)2