LAN switch logic

A LAN switch's ultimate role is to forward Ethernet frames. To achieve that goal, switches make decisions based on the source and destination MAC addresses in the Ethernet frames. 

Ethernet Header Structre
Figure 1. Ethernet Header Structure

When a switch receives a frame, it follows a set of rules and ultimately makes a decision out of which port or multiple ports to towards the frame. The switch logic can be summarized in a few steps:

  1. Receive an Ethernet frame, examine the source MAC address and update its MAC address table.
  2. Decide where and how to forward the frame based on the destination MAC address.
  3. Forward the frame out single port or forward a copy of the frame out multiple ports, if the frame is either unknown unicast or broadcast one.

Let's start with the process of receiving frames and learning MAC addresses.

Learning MAC addresses

Switches build their MAC address tables by examining the source MAC address of incoming Ethernet frames. When a frame is received on a switch port and the source MAC address is not known, the switch creates a new entry in the MAC table. 

It is important to mention that the term switchport and switch interface are used interchangeably. Also, switch's MAC address table is also called switching table and CAM table (Content-Addressable Memory Table).

Shown in figure 1 is a single-switch topology. The switch hasn't yet created any entries in its MAC address table.

LAN Switch forwarding frames and learning MAC addresses
Figure 2. LAN Switch forwarding frames and learning MAC addresses

The process starts when Client 1 sends an Ethernet frame to Client 4. Let's look closely at each steps the switch takes:

  1. An ethernet frame is received on switchport Gi0/1. Each frame starts with a 7 bytes preamble and 1 byte start frame delimiter (SFD) as shown in figure 1. These first 8 bytes of the frame are used to get the attention of the receiving node. Essentially, they tell the receiving node to get ready to receive a new frame.
  2. The switch examines the source MAC address, which is the physical address of Client 1 - 1111.1111.1111.
  3. The switch then checks this MAC address against its MAC address table. If its is not found in the table, the switch creates a new entry.
  4. Then the switch checks the destination MAC address. If there is an entry in the routing table for this address, then it sends out the frame out that interface.

The switch operations can be summarized in Figure 3.

Swtich logic summary
Figure 3. Summary of switch operations