Search in sources :

Example 6 with SetOrigin

use of org.batfish.datamodel.routing_policy.statement.SetOrigin in project batfish by batfish.

the class VirtualRouterTest method computeBgpAdvertisementsSentToOutsideIgp.

@Test
public void computeBgpAdvertisementsSentToOutsideIgp() {
    RoutingPolicy exportPolicy = _routingPolicyBuilder.setStatements(ImmutableList.of(new SetOrigin(new LiteralOrigin(OriginType.INCOMPLETE, null)), _exitAcceptStatement)).build();
    _bgpNeighborBuilder.setExportPolicy(exportPolicy.getName()).setRemoteAs(TEST_AS2).build();
    _testVirtualRouter._mainRib.mergeRoute(new OspfInternalRoute.Builder().setNetwork(TEST_NETWORK).setMetric(TEST_METRIC).setArea(TEST_AREA).setAdmin(TEST_ADMIN).setProtocol(RoutingProtocol.OSPF).build());
    // checking number of bgp advertisements
    assertThat(_testVirtualRouter.computeBgpAdvertisementsToOutside(_ipOwners), equalTo(1));
    BgpAdvertisement bgpAdvertisement = _testVirtualRouter._sentBgpAdvertisements.iterator().next();
    // checking the attributes of the bgp advertisement
    assertThat(bgpAdvertisement, hasDestinationIp(TEST_DEST_IP));
    assertThat(bgpAdvertisement, hasNetwork(TEST_NETWORK));
    assertThat(bgpAdvertisement, hasOriginatorIp(TEST_SRC_IP));
    assertThat(bgpAdvertisement, hasType(BgpAdvertisementType.EBGP_SENT));
    assertThat(bgpAdvertisement, hasSourceIp(TEST_SRC_IP));
}
Also used : BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) LiteralOrigin(org.batfish.datamodel.routing_policy.expr.LiteralOrigin) OspfInternalRoute(org.batfish.datamodel.OspfInternalRoute) SetOrigin(org.batfish.datamodel.routing_policy.statement.SetOrigin) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Test(org.junit.Test)

Example 7 with SetOrigin

use of org.batfish.datamodel.routing_policy.statement.SetOrigin 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)

Aggregations

SetOrigin (org.batfish.datamodel.routing_policy.statement.SetOrigin)7 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)5 LiteralOrigin (org.batfish.datamodel.routing_policy.expr.LiteralOrigin)5 HashSet (java.util.HashSet)3 BatfishException (org.batfish.common.BatfishException)3 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)3 If (org.batfish.datamodel.routing_policy.statement.If)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 BgpProcess (org.batfish.datamodel.BgpProcess)2 Configuration (org.batfish.datamodel.Configuration)2 Interface (org.batfish.datamodel.Interface)2 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)2 Ip (org.batfish.datamodel.Ip)2 OspfMetricType (org.batfish.datamodel.OspfMetricType)2 Prefix (org.batfish.datamodel.Prefix)2 RouteFilterLine (org.batfish.datamodel.RouteFilterLine)2 RouteFilterList (org.batfish.datamodel.RouteFilterList)2 SubRange (org.batfish.datamodel.SubRange)2 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)2