contact@embeddedgeeks.com
Embedded World

Layer 2 Switching

Layer 2 switching (or Data Link layer switching) is the process of using devices’ MAC addresses to decide where to forward frames. Switches and bridges are used for Layer 2 switching. They break up one large collision domain into multiple smaller ones.

In a typical LAN, all hosts are connected to one central device. In the past, the device was usually a hub. But hubs had many disadvantages, such as not being aware of traffic that passes through them, creating one large collision domain, etc. To overcome some of the problems with hubs, bridges were created. They were better than hubs because they created multiple collision domains, but they had a limited number of ports. Finally, switches were created and are still widely used today. Switches have more ports than bridges, can inspect incoming traffic, and make forwarding decisions accordingly. Also. each port on a switch is a separate collision domain, so no packet collisions should occur.

Layer 2 switches are faster than routers because they don’t take up time looking at the Network layer header information. Instead, they look at the frame’s hardware addresses to decide what to do with the frame – to forward, flood, or drop it. Here are other major advantages of Layer 2 switching:

  • fast hardware-based bridging (using ASICs chips)
  • wire speed
  • low latency
  • low cost

Here is an example of the typical LAN network – the switch serves as a central device that connects all devices together:

typical switch network

Differences between hubs and switches

To better understand the concept of frame switching based on the hardware address of a device, you need to understand how switches differ from hubs.

First, consider an example of a LAN in which all hosts connects to a hub:

hub network

As mentioned previously, hubs create only a single collision domain, so the chance for a collision to occur is high. The hub depicted above simply repeats the signal it receives out all ports, except the one from which the signal was received, so no frame filtering takes place. Imagine if you had 20 hosts connected to a hub, a packet would be sent to 19 hosts, instead of just one! This can also cause security problems, because an attacker can capture all traffic on the network.

how hubs work

Now consider the way the switches work. We have the same topology as above, only this time we are using a switch instead of a hub:

how switches work

Switches increase the number of collision domains. Each port is one collision domain, which means that the chances for collisions to occur are minimal. A switch learns which device is connected to which port and forwards a frame based on the destination MAC address included in the frame. This reduces traffic on the LAN and enhances security.