Switches reduce network overhead by forwarding traffic from one segment to another only when necessary. To decide whether to forward a frame, the switch uses a dynamically built table called a bridge table or MAC address table. The switch examines the address table to decide whether it should forward a frame. For example, consider the simple network shown below. Fred first sends a frame to Wilma and then one to Barney.
The switch decides to filter (in other words, to not forward) the frame that Fred sends to Wilma. Fred sends a frame with a destination MAC address of 1234.2222.2222, which is Wilma's MAC address. The switch overhears the frame, because it is attached to the left Hub. The switch then decides what common sense tells you from looking at the figure-it should not forward the frame, because Wilma, attached to the same Hub as well, already has received the frame. (Hubs simply repeat the signal out all ports, for all frames, so the switch receives everything sent by either Barney or Fred.) But how does the switch know to not forward the frame? The switch decides to filter the frame because it received the frame on port E0, and it knows that Wilma's MAC is also located out E0.
Conversely, the switch decides to forward the frame that Fred sends to Barney in the bottom part of the figure. The frame enters the switch's E0 interface, and the switch knows that the destination address, 1234.3333.3333, is located somewhere out its E1 interface. So the switch forwards the frame.
How Switches Learn MAC Addresses
The filter-versus-forward decision works best when the switch knows where all the MAC addresses are in the network. Switches dynamically learn the MAC addresses in the network to build its MAC address table. With a full, accurate MAC address table, the switch can make accurate forwarding and filtering decisions.
Switches build the MAC address table by listening to incoming frames and examining the frame's source MAC address. If a frame enters the switch, and the source MAC address is not in the address table, the switch creates an entry in the table. The MAC address is placed in the table, along with the interface in which the frame arrived.
Bridges forward LAN broadcast frames, and unknown unicast frames, out all ports. LAN broadcasts, by definition, are received by all devices on the same LAN. So the switch simply forwards broadcasts out all ports, except the one on which the broadcast was received. Switches forward unknown unicast frames, which are frames whose destination MAC addresses are not yet in the bridging table, out all ports as well. The switch floods the frame with the hope that the unknown device will be on some other Ethernet segment, it will reply, and the switch will build a correct entry in the address table.
Generally speaking, switches also forward LAN multicast frames out all ports, just like they do for broadcasts. However, a few multicast features in switches limit the flooding of multicasts, such as Internet Group Management Protocol (IGMP) snooping.
The following list provides a quick review of the basic logic a switch uses:
- A frame is received.
- If the destination is a broadcast or multicast, forward on all ports except the port on which the frame was received.
- If the destination is a unicast, and the address is not in the address table, forward on all ports except the port on which the frame was received.
- If the destination is a unicast, and the address is in the address table, and if the associated interface is not the interface on which the frame arrived, forward the frame out the one correct port.
- Otherwise, filter (do not forward) the frame.