What is the Router Switching Function
The router is a device that receives a packet from the source on any interface and forwards it to its destination on another interface. This is done by the router switching function, which encapsulates packets in the data link frame type for the outgoing data link.
The router routing function selects the best path for the packet destination, and the router switching function encapsulates the packet into the data link frame of the outgoing interface. The router switching function performs the following: receiving a packet from one network and destined for another.
1. The router receives the Layer 2 encapsulated frame and then de-encapsulates the Layer 2 frame header and trailer.
2. After De-encapsulation, the router reads Layer 3 information and the destination IP address of the IP packet to select the best path in the routing table.
3. When selecting a path for the packet destination, the router encapsulates the Layer 3 packet into a new Layer 2 frame and forwards the frame out of the exit interface.
Figures 1 to Figure 6 illustrate the packet switching over the routed network. As shown in Figure 1, the laptop generates an ICMP message for the server in the topology. The packet contains layer 3 information on the source and destination layer 3 addresses. The source layer 3 address is the address of the laptop, and the destination layer 3 address is the server’s IP address. As a packet travels from the source to the destination, the Layer 3 IP addresses do not change because the Layer 3 PDU does not change.
However, the Layer 2 data link addresses change at every hop as each router de-encapsulates and re-encapsulates the packet in a new Layer 2 frame. In Figure 1, the Layer 3 packet is encapsulated for the wireless access point and forwarded to Layer 2 (the laptop’s wireless card) and then to Layer 1 for transmitting on port 1. The wireless port is virtual, not a physical port.
Encapsulation into a different type of Layer 2 frame than the one commonly used for receiving packets is common. For example, a home router receives a frame from the wireless port and then sends it to router 3 over an Ethernet interface. So, the encapsulation for wireless and Ethernet is different. Also, encapsulation for Fast Ethernet, Giga Ethernet, and serial interfaces is different.
Figure 2 illustrates that the home router receives layer 2 packets in the shape of bits from layer 1 and then de-encapsulates the packet to read layer 3 information. When reading the source and destination, the router selects the proper outgoing interface, again encapsulates the packet, and sends it to Layer 2 and then to Layer 1.
Notice the source and destination MAC addresses and IP addresses, first on the home router and then on all the routers. At each router, the source and destination MAC addresses change, but the IP address does not change.
Also, notice in Figure 3 and Figure 4 that the ports between Router3 and Router2 have no MAC addresses in the frame. This is because this is a serial link, and MAC addresses are only required on multi-access networks, such as Ethernet. A serial link is a point-to-point connection and uses a different Layer 2 frame that does not require the MAC address.
For example, when Ethernet frames destined for Server0 are received on Router3 from the Fa0/0 interface, they are de-encapsulated and then re-encapsulated for the serial interface. When Router2 receives the frame, it is de-encapsulated again and then re-encapsulated into an Ethernet frame with a destination MAC address.
The table below better summarizes the process of sending a packet from Laptop 1 to server 0. You can see the packet source IP, MAC address, Destination IP, and MAC address.
Notice that the source and destination IP addresses do not change until the packet reaches the final destination. But the Source and destination MAC addresses change on each hop. At stage 11th, when the server responds to Laptop 1, the source and destination addresses accordingly change because now server 0 is sending a reply message to Laptop 1. So, this time, the source is server 0.