Switch – How does a switch learn a switch table

arpethernetmac addressswitch

Say the switch table is empty. If computer A sends a frame destined to computer B, the switch will broadcast asking who has the mac address of B. What if C suddenly sends a frame to A? What is the mechanism so the switch doesn't mistakenly think computer C is computer B? Is it that it remembers the mac address of the destination desired by computer A, and when C tries to get to A it also contains its own mac address and the switch sees it isn't the same destination as computer A wanted?

Basically I'm asking, when a switch floods for an unknown mac address for a request sent by host A, how does it know that the destination is responding to host A or if some other host just happens to be transmitting to A?

Best Answer

Layer 2 switches (bridges) have a MAC address table that contains a MAC address and port number. Switches follow this simple algorithm for forwarding packets:

  1. When a frame is received, the switch compares the SOURCE MAC address to the MAC address table. If the SOURCE is unknown, the switch adds it to the table along with the port number the packet was received on. In this way, the switch learns the MAC address and port of every transmitting device.

  2. The switch then compares the DESTINATION MAC address with the table. If there is an entry, the switch forwards the frame out the associated port. If there is no entry, the switch sends the packet out all its ports, except the port that the frame was received on (Flooding).

Note that the switch does not learn the destination MAC until it receives a frame from that device.

Related Topic