Basic Functions of the Switch
1. Learning: the switch learn MAC address by examine the source mac address of the each frame that it receive. If that source MAC address not in the MAC table add the MAC Address to the table. (Start aging timer)
2. Forwarding or filtering: the switchdecide where to the forward a frame based on the destination MAC address. The switch look at the previously learn MAC address in the MAC table to decide the where to forward a frame.
3. Loop Prevention: the switch create a loop free environment with other switches by using STP protocols
Switch built there MAC address table by listening to the incoming frame and examine the frame source MAC address .if that source MAC address is not in the address table then the switch creates an entry in the MAC table.
If the destination is broadcast then frame forwarded on all port except the port which was received.
If the destination is unicast and address is not in the MAC table then frame forwarded on all port except the port which was received. This process called as flooding. If the destination is unicast and MAC address is in the MAC table then the frame forwarded on a specific port only.
A switch also keeps a timer for each of the MAC address entries in its lookup table. By default, many vendors set this time to hold an address entry to 300 seconds (5 minutes). This can be changed if you want. The timer lets the switch get rid of old entries to keep the lookup process short and fast.
The aging timer also helps when a device moves to another switch port. In that case, the address would appear in both places in the lookup tables. When a frame arrives headed for that address, the switch can compare the aging timer for both entries and select the most recent if the entry has not already timed out.