So far you've learned how frames are forwarded within and across broadcast domains. Forwarding Ethernet frames within a broadcast domain is a Layer 2 decision and therefore requires a Layer 2 switch. In contrast, forwarding frames across different broadcast domains requires a router in order to move Layer 3 packets from one end-system to another. Routers use IP routing to determine the path between end-systems by manually defined static routes or dynamic routing protocols or both. Figure 3-5 gives a simple IP routing network with three Cisco routers.
Figure 3-5. A Simple IP Routing Environment
Assume in this example that each of the router's routing tables are inclusive of entries for both the client and server subnets. Each entry contains the IP subnet and next-hop address pointing to the adjacent router in the direction of the destination subnet. In order to forward frames to adjacent routers, each next-hop IP address from the routing table and its associated MAC address must reside in the ARP table on the router. Also assume in this example that ARP entries for neighboring routers have been created on the three routers, the client, and the server.
The client requesting content from the server across the network first sends the request for IP 192.168.1.1 to its default gateway router, R3. Router R3 then performs a route lookup in its routing table using the requested IP as the key to determine the closest matching routing entry. The result of the lookup is the following route for the server's subnet:
In this route, the subnet is 192.168.1.0, and the mask is 255.255.255.0. The next-hop is via R2, meaning that R1 should route the packets to the neighboring interface of R2. Using this route, router R3 routes the packet to the next-hop R2. When R2 receives the packet, it too performs a routing table lookup resulting in the entry [192.168.1.0/255.255.255.0 via R1], and in turn routes the packet to R1. R1 receives the packet, performs a route lookup, and determines that the subnet 192.168.1.0 is directly connected. R1 performs an ARP lookup for the server IP 192.168.1.1 and sends the packet to the server with the resulting MAC address.
Subnet masking involves performing a bit-wise AND operation between the mask and the IP address used as the key for the routing table lookup. The closest match route is the route with the longest subnet mask that, when masked to the requested IP, results in the subnet address of the associated routing entry. For example, when R2 uses the server IP 192.168.1.1 as key and applies the mask 255.255.255.0 associated to the entry [192.168.1.0/255.255.255.0 via R1], the result is 192.168.1.0. This matches the subnet in the routing entry; therefore, the router chooses this route for the request. If the subnet did not match, the router tries the other entries in its routing table until a match is found. If there happened to be other entries that also matched, the router would choose the entry with the longest subnet mask.
You can configure routers to populate their routing tables either by configuring static routing entries or by enabling dynamic routing protocols to automatically learn the different routes in the network.
Configuring Static Routing
To manually add routes to routing tables, use static routing. In Figure 3-6, router R1 requires knowledge of subnets 192.168.1.0/24, 192.168.2.0/24, and 192.168.3.0/24. To add these three routes to the routing table of R1, use the following static routes.
Figure 3-6. A Static Routing Environment with Manual Summary Routes
Alternatively, you can summarize these three static routes using the single static route:
Example 3-3 illustrates how to add this static route to R1.
Example 3-3. Configuring a Summary Static Route on a Router
Router R3 requires knowledge of the three subnets in the network 10.1.0.0/16. To add these three routes to the routing table of R1, use the following static routes.
Alternatively, you can summarize these three routes using the single static route:
Router R2 has directly connected interfaces in 10.1.3.0/24 and 192.168.3.0/24 but is not aware of any of the other subnets on R1 and R3. Therefore, you can add the following two summary routes to the routing table of R2 in order for it to know how to route to these subnets.
Understanding Dynamic Routing
To enable a router to automatically determine optimal paths to the subnets in a network, use dynamic routing protocols. Dynamic routing protocols can be:
These protocols exchange information between routers in order to discover network topology. If similar routes are learned by a protocol, then the route with the longest subnet mask is selected. Otherwise, the protocol's metric is used to break the tie. Dynamic protocol metrics are numeric values that specify which route should be preferred to reach the destination network.
Distance-vector metrics are calculated based on the number of router hops between end-systems. All hops are considered equal, regardless of the attributes of the links between routers. In contrast, link-state protocols intelligently calculate metrics based on the "state" of the links between routers. The metrics are based on link attributes, such as bandwidth, delay, reliability, load, and MTU. As a result, link-state metric calculations are far more processor- and memory-intensive than distance-vector metric calculations.
Distance-vector and link-state algorithms differ also in the way in which network information is discovered. With distance-vector algorithms, all or a portion of the routes from the routing table are sent to neighboring routers periodically (normally every 30 seconds), even if no changes in the network occur. When a neighboring router receives an update packet, it calculates the metric (or distance) and direction (or vector), updates its routing table, and in turn sends the update to its neighbors (except to the neighbor it came from). You can configure distance-vector protocols to filter routes before receiving and sending updates in order to prevent knowledge of certain routes from being known by particular routers in the network. Route filtering provides you with the ability to fine-tune your network routing policies.
Link-state protocols differ from distance-vector protocols in that they send updates when changes in the network occur, such as the failure of a network link or the addition of new links to the network. If no changes occur, link-state protocols send out periodic updates but less frequently than distance-vector algorithms, normally every 30 minutes.
Link-state algorithms store routes locally in a separate database before updating the main routing table. This database is called a routing information base (RIB). Each router sends its entire forwarding information base (FIB) database to its neighbors, within link-state advertisements (LSA), which in turn propagate the LSAs to neighbors, until the LSAs are received by all routers in the network. The main routing tables are not updated until all routers are aware of the LSAs from all other routers in the network. This network-wide awareness prevents those routing loops that often occur in distance-vector protocols and result from routers immediately updating routing tables directly upon reception of routing entries from their neighbors. Link-state protocols are not capable of filtering network updates in order to ensure that all routers receive the LSAs of all other routers in the network. Routing loops cannot form if routers are aware of the entire network before updating their routing tables
Hybrid protocols incorporate the efficiency of distance-vector algorithms and intelligent metric calculation of link-state algorithms. Use EIGRP to enable routers to automatically learn necessary routing information, as illustrated in Figure 3-7. Notice that EIGRP automatically summarizes the routes from the RIB for the subnets within 10.0.0.0/24 into the routing table. However, because the 192.168.x.0 networks are classful networks, EIGRP will not summarize these routes any further.
Figure 3-7. A Dynamic Routing Environment with EIGRP-Learned Routes
The routes 10.1.3.0/24 and 10.1.0.0/16 are both available in R2's routing table but have different subnet mask lengths. The first is more specific, so it will be selected as best for all traffic destined to that subnet. Figure 3-7 uses the EIGRP configurations on R1, R2, and R3 in Example 3-4.
Example 3-4. Sample EIGRP Routing Configuration
As with static routing, each dynamic routing entry in the routing table contains the destination network, mask, next-hop to the destination, and the routing protocol used to determine the route. The metric and administrative distances are also included in the routing table entry for both static and dynamic routing entries. Metrics and administrative distances are used to determine the optimal path if more than one entry is available for the same subnet.
Each routing method has an administrative distance, which assigns a priority to the protocol to help in determining the optimal path for individual routing entries. Table 3-2 gives the administrative distances for each method.
Most routers are capable of running numerous routing protocols as routing processes. Each process stores learned network information in a separate RIB, which is used to update the router's main routing table. If routes to the same destination network are installed from different processes into the routing table, the one with the longest subnet mask is selected as the best route. If routes with the same subnet mask length are installed, the administrative distances listed in Table 3-1 are used to break the tie. All inferior routes are stored in the RIBs, for later use in the case of topology change or route recalculations, if necessary.
Besides determining optimal routes, metrics and administrative distances are also used for multicast reverse path forwarding (RPF) lookups, which will be covered in Chapter 6, "Ensuring Content Delivery with Quality of Service".
Internal gateway protocols (IGPs) are used to learn subnets within an autonomous system (AS). An AS is a network or group of networks administered by the same entity, such as an organization or university. Examples of IGPs are EIGRP, OSPF, and RIP. Alternatively, external gateway protocols (EGPs) are used to route information between autonomous systems, through autonomous system border routers (ASBRs). Each AS is given a globally unique identifier, referred to as an AS number. The AS number is used for peering relationships and routing loop detection across autonomous systems.