Home > Articles > Networking > Routing & Switching

  • Print
  • + Share This
This chapter is from the book

3.7 Basic Forwarding Algorithm

This section provides an overview of the forwarding algorithm performed by the router when it is clear that the packet is not destined for the router itself and should be delivered to a remote network. The algorithm uses the following data structures:

  • Packet: the IP packet being forwarded. Each packet has fields described in Chapter 2. In particular, the forwarding algorithm uses such fields as Destination Address and Time-To-Live (TTL).

  • Interface: the network attachment description. Various characteristics are associated with each interface, including the following, which are considered interesting from the forwarding perspective:

    • Type—Can be point-to-point, point-to-multipoint, or broadcast, depending on the type of encapsulation. For example, PPP and High-Level Data Link Control (HDLC) interfaces are point-to-point; Frame Relay and X.25 interfaces are point-to-multipoint; Ethernet and Token Ring interfaces are broadcast.

    • State—Operational status—up or down—of the interface. The state of the interface is determined by the status of the physical and the data link layer protocols.

    • IP status—Flag specifying whether IP processing is enabled on the interface.

    • IP unnumbered—Flag indicating that the interface—point-to-point—is configured as unnumbered.

    • Reference interface—Interface whose IP address should be used when the packets are generated for the unnumbered interface.

    • IP address—Address assigned to the interface.

    • Address mask—Mask configured together with the IP address to specify the border between the network and hosts parts of the address.

  • Routing table—Collection of routing entries (routes). The following parameters are associated with each entry:

    • Network prefix—IP prefix—in the form of the prefix value and its length, or a network address and a route mask—that describes a collection of destinations. For example, 192.0.0.0/8, or 192.0.0.0 255.0.0.0, describes all IP hosts that are assigned IP addresses starting with 192, such as 192.1.1.1 or 192.200.150.129.

    • Default candidate—Flag indicating that the route should be considered a candidate for becoming the default route

    • Paths—Collection of next-hop structures, each corresponding to a distinct path to the destination through the network. The following parameters are associated with each path, and at least one of the two must be present.

      • Outbound interface—The interface that should be used to forward packets to the collection of destinations described by the route. If the path does not specify the interface, the route is considered recursive.

      • Intermediate address—If the path specifies the interface, this is the next-hop address that should be used to find out the data link layer details. If the path does not specify the interface, this is the address that should be used for the next iteration of the recursive routing table lookup operation.

The following algorithm is an outline of functionality performed by the routers. The packet is assumed to have passed initial checks: the sanity check (basic IP header validity verification), the inbound packet filtering policy, the TTL field check, and so on. These checks and the forwarding algorithm are discussed in more detail in Chapter 5.

  1. Set the next-hop address to the destination address in the packet.

  2. Perform recursive routing table lookup operation as follows.

    1. Find the route for the current next-hop address in the routing table.

    2. If a route is found and it specifies the intermediate address, set the next-hop address to the address in the route.

    3. If the route is found and it does not specify the interface, loop back to step 2.a.

  3. If the recursive route lookup did not succeed—no matching route was found or a route could not be resolved—send an ICMP "Destination Unreachable, Host Unreachable" message to the packet originator, using the source IP address in the packet as the destination IP address in the ICMP message, and drop the packet.

  4. Otherwise, if the current value of the next-hop address equals the prefix value of the found route, set the next-hop address back to the destination IP address in the packet.

  5. Pass the packet to the packet-delivery function. Provide the interface in the route and the current next-hop address as the arguments.

The algorithm is pretty simple. First, the routing table is searched for a route that can be used to route to the destination IP address in the packet. (The routing table lookup algorithm is discussed later.) If a route is found and it specifies only an interface—describes a directly connected network—the packet is sent out of the specified interface, using the destination IP address in the packet as the next-hop address. If the route specifies both the address and the interface—this is how IGP routes are installed—the packet is sent out of the interface to the next-hop router corresponding to the address in the route. If the route is recursive—only the intermediate address is specified—the intermediate address becomes the current next-hop route, and a routing table lookup operation is performed again.

The check in step 4 needs more explanation. That check is required when the routing table contains information similar to that shown in the following example:

10.0.0.0 is accessible via 20.1.1.0 
20.1.1.0 is directly connected to the interface Ethernet 1

The recursive route to network 10.0.0.0 specifies a subnet address (20.1.1.0) as the intermediate address. Without the check, the subnet address would be used as the next-hop address. The check makes sure that the destination address in the packet is used as the next-hop address in this situation.

The packet-delivery procedure is initiated by the forwarding algorithm and receives the packet, the outbound interface, and the next-hop IP address as the arguments from it. Following is the outline of the steps taken by the packet-delivery process.

  1. If the interface state is down or IP processing is not enabled on the interface, send an ICMP "Destination Unreachable, Host Unreachable" message to the source host, and stop processing the packet.

    NOTE

    A route in the routing table can reference an interface in down state while the routing table is converging—it takes time to remove invalid routes—or because a static route through an interface was configured to be never removed from the routing table (see Chapter 6).

  2. If the interface type is point-to-point, pass the packet directly to the packet encapsulation procedure specific to the interface. There is no need to look up data link layer details for point-to-point interfaces. They are either not necessary (such as HDLC or PPP encapsulation) or statically configured for the interface, such as, a point-to-point Frame Relay interface.

  3. Otherwise, if the interface type is point-to-multipoint, perform the following steps.

    1. Search the map table associated with the interface, using the next-hop address as the search parameter.

    2. If no map for the next-hop address is found, log an encapsulation failure, send an ICMP "Destination Unreachable, Host Unreachable" message to the source host, and stop processing the packet,

    3. Otherwise, pass the packet to the packet encapsulation procedure specific to the interface, and pass the located map table entry as a parameter; it will be used to construct the data link layer frame for the packet.

  4. Otherwise, if the interface type is broadcast, perform the following steps.

    1. Search the ARP cache for the MAC address corresponding to the next-hop address and outbound interface.

    2. If no ARP entry is found, log an encapsulation failure, send an ARP request message for the next-hop address, send an ICMP "Destination Unreachable, Host Unreachable" message to the source host, and drop the packet.

      NOTE

      Note that the router does not wait for the ARP reply message to come in and does not queue the packet.

    3. Otherwise, pass the packet to the packet encapsulation procedure specific to the interface, providing the found ARP entry as a parameter; it will be used to construct the data link layer frame for the packet.

As you can see, the data link parameters vary by type of interface. Point-to-point interfaces require very little additional work. Point-to-multipoint links, such as Frame Relay or X.25, require the DLCI or X.121, which should be used to reach a specific next-hop router. The mapping between the next-hop addresses and the data link layer details is usually configured manually by the administrator (see Chapter 5 for details). Broadcast interfaces require knowledge of the next-hop router's MAC address that is discovered using ARP. Also note that the interface MTU check and the IP packet fragmentation functionality are performed by the packet encapsulation function.

  • + Share This
  • 🔖 Save To Your Account