Port | MAC Address |
---|---|
3 | 21-76-3D-7A-F6-1E |
In this way, the switch has learned that Computer C is reachable via port 3.
After a short time, the switch will likely receive packets from all its ports and will associate the sender’s MAC address with each port:
Port | MAC Address |
---|---|
1 | 40-20-08-78-84-52 |
2 | 2F-B6-E0-F6-EA-05 |
3 | 21-76-3D-7A-F6-1E |
4 | 63-44-E4-A7-4F-E0 |
5 | 76-2F-F9-C8-B6-08 |
6 | FC-78-B6-07-52-EA |
7 | CD-34-E4-B3-2C-76 |
8 | 1C-FD-E0-63-21-C0 |
It’s important to keep in mind that a switch port might actually connect to more than one device. For example, suppose port 5 isn’t connected to a computer but to another switch, which in turn has three other computers connected to it. In that case, the first switch can receive packets from three different computers on port 5. Then, the switch records each distinct MAC address in its MAC address table, something like this:
Port | MAC Address |
---|---|
1 | 40-20-08-78-84-52 |
2 | 2F-B6-E0-F6-EA-05 |
3 | 21-76-3D-7A-F6-1E |
4 | 63-44-E4-A7-4F-E0 |
5 | 76-2F-F9-C8-B6-08 |
5 | D6-4E-69-86-E9-F7 |
5 | 06-C1-15-A2-BA-60 |
6 | FC-78-B6-07-52-EA |
7 | CD-34-E4-B3-2C-76 |
8 | 1C-FD-E0-63-21-C0 |
The process of building the MAC address table is called learning, and is one of the three basic functions of a switch. The other two are forwarding and flooding, as described in the next two sections.
Forwarding
Now that you know about the MAC address table, you should have a good idea of how a switch knows which ports to forward incoming packets to: The switch simply looks up the destination MAC address in the table and sends the packet out through the corresponding port.
For example, if the switch receives a packet on port 1 intended for MAC address CD-34-E4-B3-2C-76, the switch looks up that MAC address in the table, finds that the MAC address can be reached on port 7, and forwards the packet out to port 7. This process, called forwarding, is the second basic function of a switch.
Switches have memory buffers associated with each port that allow the switch to store a complete packet before forwarding it to the destination port. This allows the switch to hold onto the packet for a bit if necessary before forwarding it. For example, the destination port may be busy sending out a packet received from a different port. Or, the destination port may be busy receiving a packet. In either case, when the port becomes free, the switch can transmit the packet to its destination.
It’s important to understand that the switch does not modify the packet in any way prior to sending it. What gets sent out to the destination port is an exact replica of what was received on the incoming port. When the destination device receives the packet, the device has no idea that the packet passed through the switch. In other words, no tracing information is added to the packet by the switch.
It’s also important to know that, at least at this level of operation of the switch, the switch has no idea or concern for the contents of the Ethernet frame’s payload. In particular, the switch is not concerned with the possibility that the payload may be an IP packet, which in turn contains an IP address. Switching does not rely on or even know about IP addresses. Switching is a layer-2 function, and layer 2 is concerned with MAC addresses. IP addresses are a layer-3 concern and, thus, are hidden from switches.
Here’s where I have to tell you that I lied. It isn’t exactly true that switches don’t care about IP addresses. Many advanced switches have layer-3 features that do look at the IP address. But when they do, they’re acting more like routers than switches. Routers work at layer 3 and, therefore, deal with IP addresses. I have more to say about that later in this chapter, in the “Understanding Routers” section.
So, to recap, when a switch receives a packet on one of its ports, the switch looks in the Ethernet frame to determine the destination MAC address. The switch then looks that address up in its MAC address table, determines which port is associated with the destination address, and forwards the packet on to that port.
Which begs the question: What happens if the switch doesn’t recognize the destination MAC address in the forwarding database? The answer is found in the next section.
Flooding
When a switch receives a packet that is intended for a MAC address that isn’t in the switch’s internal MAC address table, the switch has no way to know what port to forward the packet to. In that case, the switch has no option but to revert to acting like a hub: The switch simply forwards the packet on all available ports other than the one the packet arrived on, of course. This is called flooding, which is the third function of a switch (the first two being learning and forwarding).
The packet will be forwarded even to ports for which the switch has already learned a MAC address. This is necessary because a single port can be a pathway to more than one MAC address, as is the case when the port is connected to another switch.
Flooding is similar to broadcasting, but it isn’t quite the same. A broadcast packet is a packet that is intended for every recipient on the network. Thus, a switch must forward broadcast packets to every port. In contrast, flooding results when the packet has a single destination, but the switch doesn’t know how to reach it. Thus, the switch sends the packet to every port in