Introduction to IP Routing

 < Day Day Up > 



Let's now discuss the routing of IP datagrams on the Internet. Prior to an IP datagram being emitted from a host, it is passed through the IP routing algorithm. This algorithm determines the next hop that the datagram must take in order to get to its destination. When a datagram is emitted from a host, the host has no idea in advance the path that the datagram will take en route to the destination. Therefore, a host worries only about the first hop or, in other words, where the datagram should be forwarded to get to its final destination.

Each device on the Internet includes a routing table. This table includes a set of networks that are available for routing in addition to a default route. The default route defines the destination for the packet if none of the prior routing entries satisfied the datagram's needs.

Simple Routing Example

Let's look at a simple example to illustrate the routing decisions from an endpoint's perspective. Consider the network topology shown in Figure 1.13.

click to expand
Figure 1.13: Sample network topology for routing discussions.

In this sample network, we'll look at routing decisions from the perspective of Host A. We can see from Figure 1.14 that Host A has an IP address of 192.168.1.1 and a network mask of 255.255.255.0. If we mask the IP address by the network mask, the result is the network on which the host resides, 192.168.1.

click to expand
Figure 1.14: Sample network device addresses.

Tip 

Note that this masking operation is based on a compact 32-bit representation. The IP address 192.168.1.1 is hex 0xC0A80101 and the network mask is 0xFFFFFF00. Using the masking operation (bitwise AND) results in 0xC0A80100, or 192.168.1.0.

Let's now look at the four cases of routing that are possible in this sample network and the decisions that are made by the IP routing algorithm. The IP routing table for Host A is provided in Figure 1.15. This table defines a destination IP address, network mask, gateway to which packets satisfied by this row should be forwarded, and the textual type of routing entry. In order to route a packet, the destination address is tested using each of the routing entries in the table. If a route is not satisfied for the IP datagram, the default route is selected (if present). Otherwise, the packet is rejected as representing an IP destination that is unreachable.

click to expand
Figure 1.15: Sample IP routing table for Host A.

Consider an application that desires to communicate with another application on the same host (otherwise known as IPC, or InterProcess Communication). In this case, the first row in the routing table (Figure 1.15) satisfies the route. Host A's IP address is 192.168.1.1, and the destination for the IP datagram (given that the destination application is on the same host) is also 192.168.1.1. Masking the destination address with the network mask results in the destination value in the routing table, 192.168.1.1. Therefore, this route is selected and the IP datagram is routed back up the stack toward the recipient application.

Now consider an application on Host A that desires to communicate with an application on Host B, whose IP address is 192.168.1.2. The destination address of the IP datagram is tested with row 2 in our routing table. Because 192.168.1.2 masked with 255.255.255.0 results in 192.168.1.0, this row is satisfied, representing a destination on the local LAN.

The next example illustrates Host A communicating with Host C. In this case, we're dealing with separate networks, so the process changes slightly. We walk through the routing table as discussed before, masking the IP datagram destination with the network mask and comparing with the route entry destination. Upon finding a match (row 3 in Figure 1.15), we now find that a gateway has been defined. In this case, the packet is forwarded to the host defined as the gateway, who will then route the packet forward to its destination.

Note 

The Address Resolution Protocol, or ARP, provides low-level address mapping between IP addresses in the Network layer and Ethernet addresses in the data-link layer for a LAN. Each Ethernet interface has a unique 48-bit address. ARP provides the mapping to the IP layer for data-link layer addressing.

Our final example illustrates what happens when a datagram is destined for an IP address that cannot be mapped by any of the local routes in the routing table. In Figure 1.15, we see that the last row specifies a destination of 0.0.0.0 and a network mask of 0.0.0.0. In this case, if we exhaust all prior routing table entries, this will satisfy the destination by default (because masking any number by 0.0.0.0 always results in 0.0.0.0). This entry is also known as the 'default route' because it's the route to all other networks.

Local (Interior) Ethernet Routing

One interesting note is the mapping of Ethernet addresses to IP addresses. Recall in our second routing example that Host A wanted to communicate with Host B. In this case, ARP identifies the Ethernet address (also known as a MAC address) for the given IP address. When the IP datagram arrives for transmission, the Ethernet header is attached with the proper Ethernet address. This simple case covers all communication for hosts on the same LAN. However, what happens when the destination host is not on the local network? In this case, the IP destination within the IP header is the actual IP address, but the Ethernet address is the address of the gateway. Therefore, the gateway receives the IP datagram, but notes that the IP address is different than its IP address. The IP datagram is then routed on toward its destination.

Exterior Routing

So, what happens when an IP datagram reaches the gateway defined by the host's routing table? The datagram is further routed using a routing daemon. One of the most commonly found routing daemons is called 'gated.' This daemon communicates with other routers to identify where IP datagrams should be forwarded. Luckily, from our perspective, all routing is local, so all we need to do is identify the first hop and let the more complicated routing daemons handle routing through the Internet.



 < Day Day Up > 



BSD Sockets Programming from a Multi-Language Perspective
Network Programming for Microsoft Windows , Second Edition (Microsoft Programming Series)
ISBN: 1584502681
EAN: 2147483647
Year: 2003
Pages: 225
Authors: Jim Ohlund

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net