|  | 11.8 | Interior Gateway Protocol (IGP) and Exterior Gateway Protocol (EGP)
| 11.8.9 | How routers use RIP to route data through a network
You have a Class B network that is divided into eight subnetworks that are connected by three routers. Host A has data it wants to send to host Z. It passes the data down through the OSI model, from the application layer to the data link layer, where host A encapsulates the data with information provided by each layer. When the data reaches the network layer, source A uses its own IP address and the destination IP address of host Z, because that is where it wants to send the data. Then, host A passes the data to the data link layer. At the data link layer, source A places the destination MAC address of the router, to which it is connected, and its own MAC address in the MAC header. Source A does this because it sees subnetwork 8 as a separate network. It knows that it cannot send data directly to a different network, but must pass such data through a default gateway. In this example, the default gateway for source A is router 1. The data packet travels along subnetwork 1. All hosts that it passes by, examine it, but do not copy it, when they see that the destination MAC address carried by the MAC header does not match their own. The data packet continues along subnetwork 1 until it reaches router 1. Like the other devices on subnetwork 1, router 1 sees the data packet, and picks it up, because it recognizes that its own MAC address is the same as the destination MAC address. Router 1 strips off the MAC header of the data and passes the data up to the network layer where it looks at the destination IP address in the IP header. The router then searches its routing tables in order to map a route, for the network address of the destination, to the MAC address of the router that is connected to subnetwork 8. The router is using RIP as its routing protocol, therefore, it determines that the best path for the data is one that places the destination only three hops away. Next, the router determines that it must send the data packet through whichever one of its ports is attached to subnetwork 4, in order for the data packet to reach its destination via the selected path. The router passes the data down to the data link layer, where it places a new MAC header on the data packet. The new MAC header contains the destination MAC address of router 2, and the MAC address of the first router that became the new source. The IP header remains unchanged. The first router passes the data packet through the port that it selects, and on to subnetwork 4. The data passes along subnetwork 4. All hosts that it passes by, examine it, but do not copy it, when they see that the destination MAC address carried by the MAC header does not match their own. The data packet continues along subnetwork 4 until it reaches router 2. Like the other devices on subnetwork 4, the router 2 sees the data packet. This time it picks it up because it recognizes that its own MAC address is the same as the destination MAC address. At the data link layer, the router strips off the MAC header, and passes the data up to the network layer. There, it examines the destination network IP address, and looks in its routing table. The router, using RIP as its routing protocol, determines that the best path for the data is one that places the destination only two hops away. Next, the router determines that it must send the data packet through whichever one of its ports is attached to subnetwork 5, in order for the data packet to reach its destination via the selected path. The router passes the data down to the data link layer where it places a new MAC header on the data packet. The new MAC header contains the destination MAC address of router 2, and the MAC address of the first router becomes the new source MAC. The IP header remains unchanged. The first router passes the data packet through the port that it selects and on to subnetwork 5. The data passes along subnetwork 5. The data packet continues along subnetwork 5 until it reaches router 3. Like the other devices on subnetwork 5, router 3 sees the data packet. This time it picks it up because it recognizes that its own MAC address is the same as the destination MAC address. At the data link layer, the router strips off the MAC header, and passes it up to the network layer. There, it sees that the destination IP address in the IP header matches that of a host that is located on one of the subnetworks to which it is attached. Next, the router determines that it must send the data packet through whichever one of its ports is attached to subnetwork 8, in order for the data packet to reach its destination address. It places a new MAC header on the data. This time, the new MAC header contains the destination MAC address of host Z, and the source MAC address of router 3. As before, the IP header remains unchanged. Router 3 sends the data through the port that is attached to subnetwork 8. The data packet travels along subnetwork 8. All hosts that it passes by, examine it, but do not copy it, when they see that the destination MAC address carried by the MAC header does not match their own. Finally, it reaches host Z, which picks it up because it sees that its MAC address matches the destination MAC address carried in the MAC header of the data packet. Host Z strips off the MAC header and passes the data to the network layer. At the network layer, host Z sees that its IP address, and the destination IP address carried in the IP header, match. Host Z strips off the IP header and passes the data up to the transport layer of the OSI model. Host Z continues to strip off the layers that encapsulate the data packet, and to pass the data to the next layer of the OSI model. This continues until the data finally arrives at the top layer, the application layer, of the OSI model.