Functions of a Network Switch, Learning, Forwarding and Preventing Layer 2 Switching Loops
Three basic functins of a switch are Learning, Forwarding and Preventing Layer 2 Loops.
Learning is the process of obtaining the MAC address of connected devices. When a frame reaches into the port of a switch, the switch reads the MAC address of the source device from Ethernet frame and compares it to its MAC address table (also known as CAM (Content Addressable Memory) table). If the switch cannot find a corresponding entry in MAC address table, the switch will add the address to the table with the port number via the Ethernet frame arrived.
If the MAC address is already available in the MAC address table, the switch compares the incoming port with the port already available in the MAC table. If the port numbers are different, the switch updates the MAC address table new port number. This will normally happen when network administrators remove the cable from one port and attach it to another port.
Whenever switch updates an entry in the MAC address table, the switch resets the timer for that entry. Timers are used in aging process of old entries. Aging helps to remove old entries and free memory of MAC address table to add new entries.
Forwarding is the process of passing network traffic a device connected to one port of a Network Switch to another device connected to another port on the switch. When a Layer 2 Ethernet frame reaches a port on the Network Switch the switch reads the source MAC address of the Ethernet frame as a part of learning function, and it also reads the destination MAC address also as a part of forwarding function. The destination MAC address is important to determine the port number which the destination device is connected.
If the destination MAC address is found on the MAC address table, the switch forwards the Ethernet frame via the corresponding port of the MAC address.
If the destination MAC address is not found on the MAC address table, the switch forwards the Ethernet frame through all its ports except the source port. This is known as flooding. Normally flooding happens when the network switch is starting up. Flooding prevents loss of traffic when the switch is learning. When the destination device receives the Ethernet frame and send a reply frame to the source device, the switch reads the MAC address of the destination device and add it to the MAC address table, which is the function of learning process.
If the source MAC address is same as the destination MAC address, the switch will drop the Ethernet frame. This is known as filtering. This will normally happen if there is a hub connected to a port of the switch, and both the source device and destination device are connected to the hub.
Preventing Layer 2 Switching Loops
In practical Local Area Networking, redundant links are created to avoid complete network failure in an event of failure in one link. Redundant links can cause layer 2 switching loops and broadcast storms. It is the function of a network switch to prevent layer 2 switching loops and broadcast storms.