After the router has determined the exit interface using the path determination function, the router needs to encapsulate the packet into the data link frame of the outgoing interface.
The switching function is the process used by a router to accept a packet on one interface and forward it out another interface. A key responsibility of the switching function is to encapsulate packets in the appropriate data link frame type for the outgoing data link.
What does a router do with a packet received from one network and destined for another network? The router performs the following three major steps:
1. Decapsulates the Layer 3 packet by removing the Layer 2 frame header and trailer.
2. Examines the destination IP address of the IP packet to find the best path in the routing table.
3. Encapsulates Layer 3 packet into a new Layer 2 frame and forwards the frame out the exit interface.
Click Play to view the animation.
As the Layer 3 IP packet is forwarded from one router to the next, the IP packet remains unchanged, with the exception of the Time To Live (TTL) field. When a router receives an IP packet, it decrements the TTL by one. If the resulting TTL value is zero, the router discards the packet. The TTL is used to prevent IP packets from traveling endlessly over networks due to a routing loop or other misfunction in the network. Routing loops are discussed in a later a chapter.
As the IP packet is decapsulated from one Layer 2 frame and encapsulated into a new Layer 2 frame, the data link destination address and source address will change as the packet is forwarded from one router to the next. The Layer 2 data link source address represents the Layer 2 address of the outbound interface. The Layer 2 destination address represents the Layer 2 address of the next-hop router. If the next hop is the final destination device, it will be the Layer 2 address of that device.
It is very likely that the packet will be encapsulated in a different type of Layer 2 frame than the one in which it was received. For example, the packet might be received by the router on a FastEthernet interface, encapsulated in an Ethernet frame, and forwarded out a serial interface encapuslated in a PPP frame.
Remember, as a packet travels from the source device to the final destination device, the Layer 3 IP addresses do not change. However, the Layer 2 data link addresses change at every hop as the packet is decapsulated and re-encapsulated in a new frame by each router.