Send to printer

At a high level, Layer 3 routers and Layer 2 switches are similar. Both look at packet headers and steer the packet toward its correct destination port, so that after being passed through the switch or router, the packet is one step closer to its desired destination.

 

Layer 2 (L2) switches are typically used to provide connectivity within high bandwidth local area networks (LANs). At its heart, an L2 switch makes forwarding decisions based on the MAC or L2 header. It extracts the L2 header from the packet, finds a matching destination address in a forwarding table, and then transmits the packet out to the port associated with that destination address in the forwarding table. The forwarding table is populated through a self-learning process, whereby each arriving packet is used to update the entries in the table. As they only have to strip through Layer 1 (the physical layer) and Layer 2 (the data link layer) in the packet to get to the useful part of the packet header, L2 switches typically implement the switching function in hardware. This allows them to steer packets at wire-speed rates without slowing down arriving streams of packets to process them.

Layer 3 (L3) routers are typically used to provide connectivity between different LANs. An L3 router discards MAC headers and indexes further into the packet, making decisions based on the IP or L3 header. It extracts the L3 header from the packet, finds a matching destination address in a routing table, identifies a new MAC address for the packet from an ARP cache, wraps the IP packet in a new MAC header, then transmits the packet out to the port associated with that destination address in the routing table. 

The routing table is populated through statically configured command line interface entries or through routing protocol messages from neighboring routers. An L3 router has to strip through Layer 1, Layer 2 and Layer 3 (the network layer), and as such, it is intrinsically more complicated than an L2 switch. Layer 3 routers historically implemented this routing function in software. That often results in limited packet-forwarding rates. However, improvements in VLSI circuit technology have allowed Layer 3 routing functions to be implemented rapidly in hardware, enabling wire-speed performance similar to the performance of L2 switches. As a result, the throughputs of next-generation L3 routers have been increasing, along with the complexity and number of lines of code.