Data Link & Physical Layers — Ethernet, MAC, Error Detection
771 words
4 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Data Link & Physical Layers — Ethernet, MAC, Error Detection ## 🎯 Learning Objectives - Explain CSMA/CD and how Ethernet handles collisions - Calculate CRC checksums - Understand MAC addressing and frame structure - Describe physical layer encoding and modulation * * * ## 1. Data Link Layer ### 1.1 Functions Func...

Data Link & Physical Layers — Ethernet, MAC, Error Detection
🎯 Learning Objectives
- Explain CSMA/CD and how Ethernet handles collisions
- Calculate CRC checksums
- Understand MAC addressing and frame structure
- Describe physical layer encoding and modulation
1. Data Link Layer
1.1 Functions
| Function | Description |
|---|---|
| Framing | Encapsulate network layer packets into frames |
| Error detection | CRC, checksum to detect transmission errors |
| Flow control | Prevent fast sender from overwhelming slow receiver |
| Medium access | Control who transmits on shared medium (CSMA/CD, CSMA/CA) |
1.2 Ethernet Frame
pseudoBytes: 7 1 6 6 2 46-1500 4 ┌──────┬──────┬────────┬──────┬──────┬──────────┬──────┐ │Preamble│SFD │ Dest │ Src │ Type │ Payload │ FCS │ │ │ │ MAC │ MAC │ │ (IP pkt) │ (CRC)│ └──────┴──────┴────────┴──────┴──────┴──────────┴──────┘
| Field | Size | Description |
|---|---|---|
| Preamble | 7 bytes | Synchronization pattern (101010...10) |
| SFD | 1 byte | Start Frame Delimiter (10101011) |
| Destination MAC | 6 bytes | Receiver's MAC address |
| Source MAC | 6 bytes | Sender's MAC address |
| Type/Length | 2 bytes | Protocol type (0x0800 = IPv4) |
| Payload | 46-1500 bytes | IP packet (with padding) |
| FCS | 4 bytes | CRC-32 checksum |
2. MAC Addressing
2.1 MAC Address Format
A MAC address is 48 bits, usually written as 6 hex octets:
AA:BB:CC:DD:EE:FF| Bits | Meaning |
|---|---|
| Bit 0 (I/G) | 0 = unicast, 1 = multicast/broadcast |
| Bit 1 (G/L) | 0 = globally unique (OUI), 1 = locally administered |
| Bits 2-23 | OUI (Organizationally Unique Identifier) |
| Bits 24-47 | NIC-specific (assigned by manufacturer) |
2.2 Special MAC Addresses
| Address | Type | Purpose |
|---|---|---|
FF:FF:FF:FF:FF:FF | Broadcast | Send to all devices on LAN |
01:80:C2:00:00:00 | Multicast | Spanning Tree Protocol |
33:33:00:00:00:01 | Multicast | IPv6 neighbor discovery |
3. CSMA/CD (Carrier Sense Multiple Access with Collision Detection)
3.1 Algorithm
(Diagram)
3.2 Exponential Backoff
After collision n, wait k \times \text{slot_time} where k is randomly chosen from [0,2n−1].
Example:
| Collision # | Range of k | Possible Wait (slot_times) |
|---|---|---|
| 1 | [0,1] | 0 or 1 |
| 2 | [0,3] | 0, 1, 2, or 3 |
| 3 | [0,7] | 0-7 |
| 16 | Abort | Frame transmission failed |
4. Error Detection: CRC
4.1 Intuition
CRC treats data as a binary polynomial, divides by a generator polynomial, and appends the remainder. The receiver performs the same division — non-zero remainder means error.
4.2 CRC Calculation Example
Data: 101101 (binary) Generator (divisor): 1101 (x³ + x² + 1)
Step 1: Append (generator_bits - 1) = 3 zeros:
101101000
Step 2: Binary division (XOR, no carry):pseudo110101 (quotient) 1101 ) 101101000 1101 ---- 1100 1101 ---- 0110 0000 ---- 1100 1101 ---- 0100 0000 ---- 1000 1101 ---- 101 (remainder = CRC)
Step 3: Transmit data + CRC:
101101101
Receiver: Divides 101101101 by 1101. Remainder = 0 → no error detected.4.3 CRC Properties
| CRC Type | Polynomial | Detects |
|---|---|---|
| CRC-1 (parity) | x + 1 | Odd number of bit flips |
| CRC-8 | x⁸ + x² + x + 1 | All ≤8-bit bursts, 99.6% of longer |
| CRC-16-IBM | x¹⁶ + x¹⁵ + x² + 1 | All ≤16-bit bursts, 99.997% |
| CRC-32 (Ethernet) | x³² + x²⁶ + x²³ + ... | All ≤32-bit bursts, >99.9999% |
5. Physical Layer
5.1 Signal Encoding
| Scheme | Bits per Baud | Example |
|---|---|---|
| NRZ | 1 | 0=V, 1=+V |
| NRZI | 1 | 0=no change, 1=toggle |
| Manchester | 1 | 0=low→high, 1=high→low |
| 4B/5B + MLT-3 | 4 bits in 5 bauds | 100BASE-TX (Fast Ethernet) |
5.2 Common Ethernet Standards
| Standard | Speed | Cable | Max Distance |
|---|---|---|---|
| 10BASE-T | 10 Mbps | Cat 3 | 100m |
| 100BASE-TX | 100 Mbps | Cat 5 | 100m |
| 1000BASE-T | 1 Gbps | Cat 5e | 100m |
| 10GBASE-T | 10 Gbps | Cat 6a | 100m |
| 40GBASE-SR4 | 40 Gbps | MMF (fiber) | 150m |
6. 📝 Practice Questions
Q1: Calculate CRC for data 110101 with generator 1001.Answer: Data: 110101000. Divide by 1001. Remainder = 011. Transmitted: 110101011.Verification: Receiver divides 110101011 by 1001 → remainder 0. Q2: What happens when two Ethernet frames collide?Answer: Both senders detect the collision (voltage spike), transmit a 32-bit jam signal, and each waits a random time (exponential backoff: wait 0 or 1 slot times for first collision, 0-3 for second, etc.). After 16 failed attempts, the frame is discarded. Q3: How does a switch learn which MAC address is on which port?Answer: The switch maintains a MAC address table. When it receives a frame, it records the source MAC and incoming port. Initially empty, it learns addresses as traffic flows. Unicast frames to unknown destinations are flooded to all ports except the source. Q4: What is the minimum Ethernet frame size and why?Answer: Minimum payload is 46 bytes (total frame = 64 bytes including header). This ensures that collisions are detected before transmission completes — the transmission time must exceed twice the propagation delay (slot time). Q5: Compare a hub, switch, and router.Answer: Hub (Layer 1): repeats signals to all ports, collision domain = all ports. Switch (Layer 2): forwards frames based on MAC address, each port is its own collision domain. Router (Layer 3): forwards packets based on IP address, connects different networks, broadcasts are not forwarded.
6. 🔗 Cross-References
- Week 3 - Network Layer: IP packets travel inside Ethernet frames
- Week 2 - Transport Layer: TCP segments inside IP packets inside Ethernet frames
- BSCS3031 (CSD): Digital signaling, encoding Join Discord PreviousIP Addressing & RoutingNextApplication Layer