Routing With a Layer 3 Switch

To understand how a typical Layer 3 switch functions, consider the network illustrated in Figure 8-26. Although it looks very similar to the network in the last example, this time the router is replaced by a Layer 3 switch. In this example, Host A is connected to one port on the switch, but is part of VLAN1. Host B is connected to another port on the same switch, but is part of VLAN2.

When the two hosts in this example attempt to communicate, the initial process is very similar. The exception is that the router interfaces that the hosts communicate with are usually virtual, or internal to the switch (in this example, the interfaces are designated using familiar names like E0 and E1). Host A will still forward the packet it has created to the router portion of the Layer 3 switch. The Layer 3 switch will still look in its routing table to determine where the packet should be forwarded next. In this case it will be forwarded out another virtual interface, and ultimately to the port where Host B resides. Note that in this case, the Layer 3 switch has still calculated the CRC, stripped away the framing, calculated the IP header checksum, determined where the packet should be forwarded next, reframed it, and sent it on its way. Some Catalyst switch models (such as a Catalyst 5000 with a Route Switch Module (RSM) installed) still forward all packets in this way. In other words, some Layer 3 switches simply add the traditional functions of a Cisco router within their hardware. The process is a little faster than using an external router, but typically not by much.

However, in other Catalyst switch models, the packet forwarding can occur at speeds closer to traditional Layer 2 switching. For example, some models support a “shortcut” feature, where after routing the first packet in the traditional manner, a Layer 3 switch gets smart and uses pattern matching (via specialized hardware) to speed up the process of forwarding additional packets. In this example, the switch would recognize that it passed a frame up to Layer 3, only to have it forwarded back to itself. Instead of sending all other packets in this session from Host A to Host B up to Layer 3, the switch would instead rewrite the frame header automatically at Layer 2, making it appear as though the packet has passed through the router. In fact, once the process is complete, it is impossible to distinguish a packet that has been forwarded in this manner from one that has been routed traditionally.

After the first packet in the stream between Hosts A and B has been routed the old fashioned way, the switch caches the appropriate information it need to rewrite the packet. In this case, it knows that when it receives packets with the source MAC address of Host A, a destination MAC address of the virtual router interface, and the source and destination IP addresses of Hosts A and B respectively, it can rewrite the header using the shortcut information it has gathered by pattern matching. In this case, it will add new source and destination MAC addresses to the frame, decrement the TTL, recalculate the IP header checksum, and then switch the packet out the port that Host A is attached to – all without sending the packet up to Layer 3. When a Layer 3 switch functions in this manner, routing takes place at speeds closer to traditional Layer 2 switching.