TCP/IP Defined - Routing

 

Within an internet, it is possible to send a datagram over many paths to a given address. A datagram is a unit of information that contains a source and destination address, plus data. Routing is the process of choosing which path or route is best.

Basically, there are two kinds of routing: direct and indirect.

You can route a datagram directly when the sending and receiving hosts are in the same network.

You must route a datagram indirectly when the sending and receiving hosts are in different networks. In this case the datagram first goes to a local gateway. The local gateway decides where to send the datagram next. The datagram “hops” from one gateway to another until it reaches a gateway connected to the destination network. The final gateway then sends the datagram to the destination host.

 

Routing Tables

All hosts and gateways on a network store routing information in tables. Each record in a routing table usually contains:

  • A destination internet address
  • The internet address of a gateway that is physically connected to the same network
  • A flag that determines whether the route is a host route or a network route (The next section, Host Routing versus Network Routing, explains the difference between these two kinds of routing.)
  • A flag that determines whether to use a direct or indirect route

Some routing tables also contain information about network performance (for example, whether specific network interfaces are up or down) to help regulate the flow of network traffic. Table 3 contains a sample routing table.

Table 3 Sample Routing Table
Destination Address Gateway Address Host or Network Route? Direct or Indirect Route?
89.0.0.0 89.23.1.4 Network Indirect
91.2.4.5 89.23.1.4 Host Indirect
25.0.0.0 90.11.5.3 Network Indirect
89.4.5.7 89.23.1.4 Host Direct

 

Host Routing Versus Network Routing

The host or network routing flag determines how the host or gateway compares the datagram's destination internet address with the destination address in the routing table.

Upon finding a host routing record, the host or gateway compares all parts of the datagram's destination internet address with the destination address defined in the routing record. Both addresses must match exactly for the datagram to use the route defined in that record. This is shown in Figure 5.

Figure 5: Host Routing

Upon finding a network routing record, the host or gateway compares only the network or subnet portion of the datagram's destination internet address with the destination address defined in the routing record. Both addresses must have the same network or subnet numbers for the datagram to use the route defined in that record. The host portion of the address is irrelevant.

Figure 6: Network Routing

Assume that the internet addresses shown in Figure 6 belong to a Class A network that is not subnetted. The first byte of the address specifies a network. The remaining bytes are host numbers. The network routing record defines only the network portion of the destination address (91.0.0.0).

 

How Datagrams Are Routed

A host or gateway does the following to send a datagram:

  1. Search the routing table for a matching host route entry. If one is not found, it proceeds to step 2. If an entry is found, it goes to step 4.
  2. Search the routing table for a matching network route entry. If one is not found, it proceeds to step 3. If an entry is found, it goes to step 4.
  3. Search the routing table for a default route. Typically, this is a network route with a destination address of O.O.O.O. If one is found, it proceeds to step 4; otherwise, it discards the datagram. If the host is a gateway, it might send an Internet Control Message Protocol (ICMP) redirect message to inform the original sender that no route exists. (See the section Routing Table Maintenance for a description of ICMP redirect messages.)
  4. Look for the direct/indirect routing flag. If direct routing is enabled, the host sends the datagram directly to the destination host, using the network device specified by the gateway internet address. If indirect routing is enabled, the host sends the datagram to the gateway internet address defined in the routing record.

 

Routing Table Maintenance

Routing tables are maintained in two ways: manually or dynamically.

The system manager maintains routing tables manually by adding and deleting records. Gateways can maintain routing tables dynamically by sending Internet Control Message Protocol (ICMP) redirect messages to hosts and other gateways in response to routing requests. These messages advise the hosts and gateways of the best way to route datagrams. Hosts and gateways use the ICMP messages to update routing tables automatically.

The example in Figure 7 shows how ICMP redirect messages work.

Figure 7: Dynamic Maintenance via ICMP

Suppose Harpo wants to send a datagram to Bart. This is what happens:

  1. Harpo's routing table instructs the host to send the datagram to Gateway Zeno. Harpo complies (datagram hop 1).
  2. Zeno checks its routing table, which directs Zeno to send the datagram to Gateway Plato. However, Zeno knows that Plato is directly connected to both Network 1 and Network 2.
  3. Zeno sends the datagram to Plato (datagram hop 2). It also sends an ICMP redirect message informing Harpo to send datagrams directly to Plato when Harpo needs to communicate with Bart.
  4. Plato forwards the datagram to Bart (datagram hop 3).
  5. Harpo updates its routing tables to include the new information. Now when Harpo communicates with Bart, fewer hops are necessary.

You can also have a routing process (GateD, the Gateway routing daemon) that communicates with routers using protocols such as Routing Information Protocol (RIP) or Open Shortest Path First (OSPF). These protocols learn about routes and dynamically add them to the routing table.