Sub topic 3
Why Switches Replaced Hubs
This chapter assumes you know what a MAC address is, how it differs from an IP address, and the fields of an Ethernet frame (destination MAC, source MAC, EtherType). It also assumes you can tell a hub, a switch and a router apart at a high level. The goal here is to explain why the switch's MAC address table exists, by looking at what a hub could not do.
How a hub behaves
A hub is a Layer 1 device. It does not read frames. It receives an electrical signal on one port, regenerates it, and repeats it out of every other port. It has no memory and no address table, because it never looks at an address.
Every device on a hub therefore receives every frame. A network interface card (NIC) normally compares the destination MAC address with its own and discards frames meant for someone else. The hub does nothing to limit who sees the traffic. The NIC only ignores it politely.
Two consequences follow:
- Everyone can read everything. Any host that turns off the destination filter (promiscuous mode) sees all traffic on the segment.
- Everyone shares one pipe. Only one device can transmit at a time.
Collision domains and CSMA/CD
A collision domain is the set of devices whose transmissions can interfere with each other. All the ports of a hub belong to one collision domain, because the hub simply repeats electrical signals.
Classic half-duplex Ethernet handles this with CSMA/CD (carrier sense multiple access with collision detection):
- A host listens. If the wire is busy, it waits.
- If the wire is idle, it starts sending and keeps listening.
- If it detects another signal at the same time, a collision has occurred. Both hosts stop, send a short jam signal, and wait a random time (binary exponential backoff) before trying again.
Collisions are normal in this design, not a fault. They do waste capacity, and the waste grows with the number of hosts and the amount of traffic. Shared bandwidth is also divided among all hosts: ten hosts on a 100 Mb/s hub share 100 Mb/s in total, so each gets roughly 10 Mb/s under load.
Chaining hubs makes things worse. Connecting two hubs merges their collision domains into one larger domain. CSMA/CD also limits the physical size of that domain, because a sender must still be transmitting when the collision signal returns from the far end.
What a switch changes
A switch is a Layer 2 device. It reads each frame's destination and source MAC addresses and makes a decision per frame. It forwards the frame only toward the port where the destination lives, when it knows that port.
That single change has three effects.
Each port is its own collision domain
A switch buffers a frame in memory before sending it. Each port has its own link, so a host on port 1 and a host on port 2 can transmit at the same moment. The switch stores their frames and sends them out one at a time on whichever outgoing port is needed. The collision domain shrinks to one link: the cable between the switch port and the host.
When that link runs full duplex, the NIC and the switch port transmit and receive on separate paths at the same time. CSMA/CD is switched off, and collisions on that link cannot happen. Every host gets the full link speed, not a share of it.
Unicast traffic stays private
If a switch knows that host B is on port 2, a frame from A to B goes out of port 2 only. Host C on port 3 never receives it. This reduces both the load on every other link and the opportunity for casual eavesdropping.
Broadcast domains are unchanged
A switch still floods broadcasts out of every port, so all ports of a plain switch share one broadcast domain. Replacing a hub with a switch removes collision problems. It does not shrink the broadcast domain. Splitting a broadcast domain needs VLANs or a router, which later chapters cover.
| Property | Hub | Switch |
|---|---|---|
| OSI layer | 1 (physical) | 2 (data link) |
| Reads MAC addresses | No | Yes |
| Collision domains | One for the whole device | One per port |
| Bandwidth | Shared among all ports | Dedicated per port |
| Duplex | Half duplex only | Full duplex typical |
| Known unicast | Repeated to all ports | Sent to one port |
| Broadcast domains | One | One (without VLANs) |
| Needs an address table | No | Yes |
Why the switch needs a MAC address table
To send a frame to only one port, the switch must know which port leads to each destination. There are two ways to provide that knowledge.
- Manual configuration. An administrator types in every host's MAC address and port. This is correct but does not scale. Every NIC replacement, laptop and virtual machine would need an edit.
- Automatic learning. The switch builds the mapping itself from the traffic it sees.
Switches use learning. The result is a MAC address table, also called the CAM table (after the content-addressable memory hardware that many switches use for fast lookup). Each entry pairs a MAC address with a port, and usually a VLAN and a timestamp used for aging. The next chapters explain how the table is filled, read and aged.
The key property is that a switch is plug and play. You connect cables and the device begins forwarding correctly with no configuration, because every frame it receives teaches it something about where its sender lives.
What the switch still shares with a hub
A switch with an empty table behaves like a hub. It does not yet know any location, so it sends each frame out of every port except the one it arrived on. This is called flooding. The difference is that a hub floods always, while a switch floods only until it has learned the destination, and for broadcasts and multicasts that need it.
The following diagram contrasts the two devices for the same frame, after the switch has learned all hosts.
Common errors and misconceptions
- "A switch isolates broadcasts." It does not. Without VLANs, broadcasts reach every port.
- "Switches are always collision-free." Only full-duplex links are. A port that negotiates half duplex, often because of a duplex mismatch with a misconfigured peer, still sees collisions and late collisions. A mismatch typically shows up as slow throughput and rising error counters on one link.
- "Switched traffic cannot be sniffed." Traffic is less exposed, not safe. A capture on another host does not see unicast frames meant for someone else under normal conditions. However, a full table can be abused (covered in a later chapter on MAC flooding), and flooded frames reach everyone. Use encryption if confidentiality matters.
- "A switch forwards at the speed of the sender." A switch can drop frames when several ports send to one output port faster than that port can drain. Per-port buffers absorb short bursts only.
Why hubs disappeared
Several pressures pushed hubs out of use:
- Price. Switching chips became cheap enough to cost about the same as a repeater.
- Throughput. Applications such as file sharing, and later video and voice, needed more than a share of a segment.
- Full duplex. It doubled the effective capacity of a link, and it needs a device that buffers frames, which a hub cannot do.
- Mixed speeds. A switch buffers frames, so a 1 Gb/s port and a 100 Mb/s port can talk. A hub needs all ports at the same speed.
- Security and management. Per-port visibility, counters, VLANs and port security need a device that understands frames.
Today a hub appears mainly in teaching labs or as a legacy device. Network taps and port mirroring (SPAN) have replaced the old trick of putting a hub in the path to capture traffic.
Exercise
Six hosts connect to a hub, and six other hosts connect to a switch. All links are 100 Mb/s. (a) How many collision domains does each device create when the switch links run full duplex? (b) Host 1 sends a unicast frame to host 2 in both setups, and the switch has already learned host 2. Which other hosts receive the frame? (c) A broadcast is sent in each setup. Which hosts receive it?
Show answer
(a) The hub creates one collision domain for all six hosts. The switch creates six, one per port, and with full duplex none of them can have collisions. (b) On the hub, hosts 2 to 6 all receive the frame, and hosts 3 to 6 discard it because the destination MAC does not match. On the switch, only host 2 receives it. (c) In both setups every other host receives the broadcast, because a switch without VLANs floods broadcasts out of all ports. The broadcast domain stays the same.
Exercise
A learner replaces a hub with a switch and expects broadcast traffic to drop. It does not. Explain why, and name two ways to reduce the size of the broadcast domain.
Show answer
A switch floods broadcast frames out of every port except the ingress port, exactly as the hub did, so the broadcast domain is unchanged. Only collision domains shrink. You can reduce the broadcast domain by configuring VLANs on the switch, or by placing a router (or Layer 3 interface) between groups of hosts.