Search in sources :

Example 1 with RipInternalRoute

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

the class VirtualRouter method propagateRipInternalRoutes.

/**
 * Process RIP routes from our neighbors.
 *
 * @param nodes Mapping of node names to Node instances
 * @param topology The network topology
 * @return True if the rib has changed as a result of route propagation
 */
boolean propagateRipInternalRoutes(Map<String, Node> nodes, Topology topology) {
    boolean changed = false;
    // No rip process, nothing to do
    if (_vrf.getRipProcess() == null) {
        return false;
    }
    String node = _c.getHostname();
    int admin = RoutingProtocol.RIP.getDefaultAdministrativeCost(_c.getConfigurationFormat());
    SortedSet<Edge> edges = topology.getNodeEdges().get(node);
    if (edges == null) {
        // there are no edges, so RIP won't produce anything
        return false;
    }
    for (Edge edge : edges) {
        // Do not accept routes from ourselves
        if (!edge.getNode1().equals(node)) {
            continue;
        }
        // Get interface
        String connectingInterfaceName = edge.getInt1();
        Interface connectingInterface = _vrf.getInterfaces().get(connectingInterfaceName);
        if (connectingInterface == null) {
            // wrong vrf, so skip
            continue;
        }
        // Get the neighbor and its interface + VRF
        String neighborName = edge.getNode2();
        Node neighbor = nodes.get(neighborName);
        String neighborInterfaceName = edge.getInt2();
        Interface neighborInterface = neighbor._c.getInterfaces().get(neighborInterfaceName);
        String neighborVrfName = neighborInterface.getVrfName();
        VirtualRouter neighborVirtualRouter = nodes.get(neighborName)._virtualRouters.get(neighborVrfName);
        if (connectingInterface.getRipEnabled() && !connectingInterface.getRipPassive() && neighborInterface.getRipEnabled() && !neighborInterface.getRipPassive()) {
            /*
         * We have a RIP neighbor relationship on this edge. So we should add all RIP routes
         * from this neighbor into our RIP internal staging rib, adding the incremental cost
         * (?), and using the neighborInterface's address as the next hop ip
         */
            for (RipInternalRoute neighborRoute : neighborVirtualRouter._ripInternalRib.getRoutes()) {
                long newCost = neighborRoute.getMetric() + RipProcess.DEFAULT_RIP_COST;
                Ip nextHopIp = neighborInterface.getAddress().getIp();
                RipInternalRoute newRoute = new RipInternalRoute(neighborRoute.getNetwork(), nextHopIp, admin, newCost);
                if (_ripInternalStagingRib.mergeRoute(newRoute)) {
                    changed = true;
                }
            }
        }
    }
    return changed;
}
Also used : RipInternalRoute(org.batfish.datamodel.RipInternalRoute) Ip(org.batfish.datamodel.Ip) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Example 2 with RipInternalRoute

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

the class RipInternalRibTest method testComparePreference.

@Test
public void testComparePreference() {
    RipInternalRib rib = new RipInternalRib(null);
    RipInternalRoute r1 = new RipInternalRoute(Prefix.parse("10.1.0.0/16"), Ip.AUTO, RoutingProtocol.RIP.getDefaultAdministrativeCost(ConfigurationFormat.CISCO_IOS), 10);
    RipInternalRoute r2 = new RipInternalRoute(Prefix.parse("10.1.0.0/16"), Ip.AUTO, RoutingProtocol.RIP.getDefaultAdministrativeCost(ConfigurationFormat.CISCO_IOS), 12);
    assertThat(rib.comparePreference(r1, r1), equalTo(0));
    assertThat(rib.comparePreference(r1, r2), greaterThan(0));
    assertThat(rib.comparePreference(r2, r1), lessThan(0));
}
Also used : RipInternalRoute(org.batfish.datamodel.RipInternalRoute) Test(org.junit.Test)

Example 3 with RipInternalRoute

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

the class VirtualRouterTest method testRipInitialization.

/**
 * Check that initialization of RIP internal routes happens correctly
 */
@Test
public void testRipInitialization() {
    // Incomplete Setup
    VirtualRouter vr = makeIosVirtualRouter(null);
    addInterfaces(vr._c, exampleInterfaceAddresses);
    vr.initRibs();
    vr.initBaseRipRoutes();
    // Check that nothing happens
    assertThat(vr._ripInternalRib.getRoutes(), is(emptyIterableOf(RipInternalRoute.class)));
    // Complete setup by adding a process
    RipProcess ripProcess = new RipProcess();
    ripProcess.setInterfaces(vr._vrf.getInterfaceNames());
    vr._vrf.setRipProcess(ripProcess);
    vr.initBaseRipRoutes();
    assertThat(vr._ripInternalRib.getRoutes(), containsInAnyOrder(exampleInterfaceAddresses.values().stream().map(address -> new RipInternalRoute(address.getPrefix(), null, RoutingProtocol.RIP.getDefaultAdministrativeCost(vr._c.getConfigurationFormat()), RipProcess.DEFAULT_RIP_COST)).collect(Collectors.toList()).toArray(new RipInternalRoute[] {})));
    vr._ripInternalRib.getRoutes();
}
Also used : RipInternalRoute(org.batfish.datamodel.RipInternalRoute) RipProcess(org.batfish.datamodel.RipProcess) Test(org.junit.Test)

Example 4 with RipInternalRoute

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

the class VirtualRouter method initBaseRipRoutes.

/**
 * Initialize RIP routes from the interface prefixes
 */
@VisibleForTesting
void initBaseRipRoutes() {
    if (_vrf.getRipProcess() == null) {
        // nothing to do
        return;
    }
    // init internal routes from connected routes
    for (String ifaceName : _vrf.getRipProcess().getInterfaces()) {
        Interface iface = _vrf.getInterfaces().get(ifaceName);
        if (iface.getActive()) {
            Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream().map(InterfaceAddress::getPrefix).collect(Collectors.toSet());
            long cost = RipProcess.DEFAULT_RIP_COST;
            for (Prefix prefix : allNetworkPrefixes) {
                RipInternalRoute route = new RipInternalRoute(prefix, null, RoutingProtocol.RIP.getDefaultAdministrativeCost(_c.getConfigurationFormat()), cost);
                _ripInternalRib.mergeRoute(route);
            }
        }
    }
}
Also used : RipInternalRoute(org.batfish.datamodel.RipInternalRoute) Prefix(org.batfish.datamodel.Prefix) Interface(org.batfish.datamodel.Interface) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RipInternalRoute (org.batfish.datamodel.RipInternalRoute)4 Interface (org.batfish.datamodel.Interface)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Edge (org.batfish.datamodel.Edge)1 Ip (org.batfish.datamodel.Ip)1 Prefix (org.batfish.datamodel.Prefix)1 RipProcess (org.batfish.datamodel.RipProcess)1