CSMA/CD
This module explores the core principles of CSMA/CD, deriving solutions from first principles and hardware constraints to build world-class, production-ready expertise.
1. The Shared Medium Problem
Imagine walking into a chaotic cocktail party where everyone is in a single room, sharing the same air to speak (a Shared Medium). If two people start talking loudly at the exact same millisecond, their voices overlap into an unintelligible mess. In early Ethernet (Bus topology using Hubs or coaxial cables), all devices shared the exact same physical copper wire. If two Network Interface Cards (NICs) transmitted simultaneously, the voltage signals overlapped and corrupted the frame. This event is called a Collision.
To prevent the entire network from breaking down into a permanent state of corrupted data, engineers needed a decentralized, robust protocol to handle who gets to “speak” and how to recover when two people speak at once.
2. Anatomy of CSMA/CD
Carrier Sense Multiple Access with Collision Detection. Let’s break down each component:
- Carrier Sense: “Listen before you talk.” Before a NIC attempts to send a frame, it listens to the wire to check if any voltage changes (a carrier signal) are present. If someone else is transmitting, it waits.
- Multiple Access: Everyone has an equal right to use the wire. There is no central “master” node dictating when devices can send data. It’s fully decentralized.
- Collision Detection: “Listen to yourself.” Even while transmitting, the NIC continues to listen to the wire. If the signal detected on the wire is different from the signal the NIC is actively sending (e.g., the voltage spikes beyond normal transmission levels because two signals added together), a collision is detected.
The Minimum Frame Size Constraint
For Collision Detection to work reliably, a device must still be transmitting its frame when the collision reaches it. If a frame is too small, a device might finish sending the frame before the collision travels back down the wire. The device would falsely assume the frame arrived perfectly.
To solve this, Ethernet enforces a Minimum Frame Size of 64 bytes. If a frame is smaller than 64 bytes, padding is added to ensure the transmission lasts long enough for the signal to propagate across the maximum allowed cable length (e.g., 2500 meters in 10BASE5) and back.
3. Case Study: Handling a Collision (PEDALS Framework)
Let’s look at the exact procedure of handling a collision through the PEDALS framework to understand the system design underlying this legacy architecture.
- Process Requirements: Recover gracefully from a collision without central coordination, preventing the network from immediately colliding again.
- Estimate: In a network of 10 nodes, if all 10 nodes collide and retry at the exact same time, the probability of a secondary collision is 100%. We need to exponentially decrease this probability.
- Data Model / Signals: A special 48-bit Jam Signal must be used to alert all nodes.
- Architecture: Decentralized randomized backoff timers on each individual NIC.
- Localized Details: When a collision is detected, the transmitting NIC immediately stops sending data and transmits the Jam Signal. This ensures every node on the wire registers the collision, even if they were far away.
- Scale (Binary Exponential Backoff): Each device then picks a random wait time before trying again. The wait time is calculated in “slot times” (51.2 microseconds for 10Mbps Ethernet).
- First collision: Wait 0 or 1 slot.
- Second collision: Wait 0, 1, 2, or 3 slots (\(2^2 - 1\)).
- Nth collision: Wait a random number of slots between 0 and \(2^N - 1\).
- The window doubles every time (up to 10 tries), exponentially reducing the chance of a recurring collision. After 16 attempts, the frame is dropped entirely and an error is reported to the upper layers.
4. Interactive: Collision Simulation
Try to send from two nodes simultaneously.
5. Modern Implementation (Why we don’t use it anymore)
Modern Ethernet relies entirely on Switches rather than Hubs. A Switch creates a dedicated point-to-point link between itself and the NIC on an individual port.
- This is a Full-Duplex link (one twisted pair for Transmit/TX, one completely separate pair for Receive/RX).
- Because transmit and receive occur on completely separate physical wires, collisions are physically impossible.
- CSMA/CD logic is now only kept in the IEEE 802.3 standard for backward compatibility (in case a modern device is plugged into a legacy hub).
Collision Domain: The set of devices where a collision can occur.
- Hub: Acts as 1 giant collision domain. All connected devices share the wire.
- Switch: Micro-segments the network. Every individual port is its own separate collision domain.