Path Determination and Switching Function Details
Can you describe the exact details of what happens to a packet at Layer 2 and Layer 3 as it travels from source to destination? If not, study the animation and follow along with the discussion until you can describe the process on your own.
Click Play to view the animation.
Step 1: PC1 has a packet to be sent to PC2
PC1 encapsulates the IP packet into an Ethernet frame with the destination MAC address of R1's FastEthernet 0/0 interface.
How does PC1 know to forward to packet to R1 and not directly to PC2? PC1 has determined that the IP source and IP destination addresses are on different networks.
PC1 knows the network it belongs to by doing an AND operation on its own IP address and subnet mask, which results in its network address. PC1 does this same AND operation using the packet destination IP address and the PC1 subnet mask. If the result is the same as its own network, PC1 knows that the destination IP address is on its own network and it does not need to forward the packet to the default gateway, the router. If the AND operation results in a different network address, PC1 knows that the destination IP address is not on its own network and that it must forward this packet to the default gateway, the router.
Note: If an AND operation with the destination IP address of the packet and the subnet mask of PC1 results in a different network address than what PC1 has determined to be its own network address, this address does not necessarily reflect the actual remote network address. PC1 only knows that if the destination IP address is on its own network, the masks will be the same and the network addresses would be the same. The mask of the remote network might be a different mask. If the destination IP address results in a different network address, PC1 will not know the actual remote network address - it only knows that it is not on its own network.
How does PC1 determine the MAC address of the default gateway, router R1? PC1 checks its ARP table for the IP address of the default gateway and its associated MAC address.
What if this entry does not exist in the ARP table? PC1 sends an ARP request and router R1 sends back an ARP reply.
Step 2: Router R1 receives the Ethernet frame
1. Router R1 examines the destination MAC address, which matches the MAC address of the receiving interface, FastEthernet 0/0. R1 will therefore copy the frame into its buffer.
2. R1 sees that the Ethernet Type field is 0x800, which means that the Ethernet frame contains an IP packet in the data portion of the frame.
3. R1 decapsulates the Ethernet frame.
4. Because the destination IP address of the packet does not match any of R1's directly connected networks, the router consults its routing table to R1's directly connected networks, the router consults its routing table to route this packet. R1 searches the routing table for a network address and subnet mask that would include this packet's destination IP address as a host address on that network. In this example, the routing table has a route for the 192.168.4.0/24 network. The destination IP address of the packet is 192.168.4.10, which is a host IP address on that network.
R1's route to the 192.168.4.0/24 network has a next-hop IP address of 192.168.2.2 and an exit interface of FastEthernet 0/1. This means that the IP packet will be encapsulated in a new Ethernet frame with the destination MAC address of the next-hop router's IP address. Because the exit interface is on an Ethernet network, R1 must resolve the next-hop IP address with a destination MAC address.
5. R1 looks up the next-hop IP address of 192.168.2.2 in its ARP cache for its FastEthernet 0/1 interface. If the entry is not in the ARP cache, R1 sends an ARP request out its FastEthernet 0/1 interface. R2 sends back an ARP reply. R1 then updates its ARP cache with an entry for 192.168.2.2 and the associated MAC address.
6. The IP packet is now encapsulated into a new Ethernet frame and forwarded out R1's FastEthernet 0/1 interface.