Search in sources :

Example 1 with ConnectedRoute

use of org.batfish.datamodel.ConnectedRoute in project batfish by batfish.

the class VirtualRouterTest method testInitConnectedRib.

/**
 * Check that initialization of Connected RIB is as expected
 */
@Test
public void testInitConnectedRib() {
    // Setup
    VirtualRouter vr = makeIosVirtualRouter(null);
    addInterfaces(vr._c, exampleInterfaceAddresses);
    vr.initRibs();
    // Test
    vr.initConnectedRib();
    // Assert that all interface prefixes have been processed
    assertThat(vr._connectedRib.getRoutes(), containsInAnyOrder(exampleInterfaceAddresses.entrySet().stream().map(e -> new ConnectedRoute(e.getValue().getPrefix(), e.getKey())).collect(Collectors.toList()).toArray(new ConnectedRoute[] {})));
}
Also used : ConnectedRoute(org.batfish.datamodel.ConnectedRoute) Test(org.junit.Test)

Example 2 with ConnectedRoute

use of org.batfish.datamodel.ConnectedRoute in project batfish by batfish.

the class VirtualRouter method initConnectedRib.

/**
 * Initialize the connected RIB -- a RIB containing connected routes (i.e., direct connections to
 * neighbors).
 */
@VisibleForTesting
void initConnectedRib() {
    // Look at all connected interfaces
    for (Interface i : _vrf.getInterfaces().values()) {
        if (i.getActive()) {
            // Create a route for each interface prefix
            for (InterfaceAddress ifaceAddress : i.getAllAddresses()) {
                Prefix prefix = ifaceAddress.getPrefix();
                ConnectedRoute cr = new ConnectedRoute(prefix, i.getName());
                _connectedRib.mergeRoute(cr);
            }
        }
    }
}
Also used : ConnectedRoute(org.batfish.datamodel.ConnectedRoute) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Prefix(org.batfish.datamodel.Prefix) Interface(org.batfish.datamodel.Interface) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ConnectedRoute

use of org.batfish.datamodel.ConnectedRoute 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

ConnectedRoute (org.batfish.datamodel.ConnectedRoute)3 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 AsPath (org.batfish.datamodel.AsPath)1 Interface (org.batfish.datamodel.Interface)1 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)1 Prefix (org.batfish.datamodel.Prefix)1 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)1 LiteralOrigin (org.batfish.datamodel.routing_policy.expr.LiteralOrigin)1 SetOrigin (org.batfish.datamodel.routing_policy.statement.SetOrigin)1