Framing, error detection, MAC addressing, and access control
Layer 2 - Reliable node-to-node data transfer
| Function | Description |
|---|---|
| Framing | Divide data into manageable frames |
| Addressing | MAC (physical) addressing |
| Error Detection | CRC, checksum, parity |
| Flow Control | Prevent buffer overflow |
| Access Control | Manage shared medium access |
┌─────────────────────────────────┐
│ LLC (Logical Link │ ← Flow control, error detection
│ Control) │ ← Interface to Network layer
├─────────────────────────────────┤
│ MAC (Media Access │ ← Physical addressing
│ Control) │ ← Channel access control
└─────────────────────────────────┘
Frame = Data Link PDU
┌────────┬──────────────┬─────────────┬────────┬─────────┐
│ Header │ Source MAC │ Dest MAC │ Data │ Trailer │
│ (Flag) │ (6 bytes) │ (6 bytes) │(Payload)│ (CRC) │
└────────┴──────────────┴─────────────┴────────┴─────────┘
| Method | Description |
|---|---|
| Character Count | First byte = frame length |
| Byte Stuffing | Special flag bytes mark start/end |
| Bit Stuffing | Flag pattern with stuffed bits |
Bit Stuffing Example:
Flag: 01111110
Data: 011111110 (problematic - looks like flag!)
After stuffing: 0111110110 (add 0 after five 1s)
Receiver removes extra 0s
Even Parity: Total 1s should be even
Data: 1011001 (four 1s) → Parity bit = 0 → 10110010
Data: 1011011 (five 1s) → Parity bit = 1 → 10110111
Limitation: Only detects odd number of errors!
# Add all data bytes, take complement
data = [0x1234, 0x5678, 0x9ABC]
total = sum(data) # = 0x1E248
# Fold overflow and complement
checksum = ~total & 0xFFFF
# Receiver adds all including checksum
# Result should be 0xFFFF (all 1s)
Most powerful error detection method.
CRC Process:
1. Append n-1 zeros to data (where n = divisor bits)
2. Divide by generator polynomial using XOR
3. Remainder = CRC (append to data)
4. Receiver divides: remainder 0 = no error
Example:
Data: 1010, Generator: 1011 (CRC-3)
Append 3 zeros: 1010000
Divide by 1011 → Remainder = 011
Send: 1010011
MAC = Media Access Control (Physical Address)
Format: XX:XX:XX:XX:XX:XX (48 bits / 6 bytes)
Example: 00:1A:2B:3C:4D:5E
First 3 bytes (OUI): Manufacturer ID
Last 3 bytes (NIC): Device ID
Special Addresses:
FF:FF:FF:FF:FF:FF = Broadcast (all devices)
| MAC Address | IP Address |
|---|---|
| Physical (hardware) | Logical (software) |
| 48 bits (6 bytes) | 32 bits (IPv4) |
| Never changes | Can change |
| Local network use | Global routing |
| Layer 2 | Layer 3 |
Sender Receiver
|---Frame 0--->|
|<----ACK------|
|---Frame 1--->|
|<----ACK------|
Simple but slow (waits for each ACK)
Window Size = 4
Sender can send frames 0,1,2,3 without waiting
Sender Receiver
|---Frame 0--->|
|---Frame 1--->|
|---Frame 2--->|
|<----ACK 2----|
|---Frame 3--->|
|---Frame 4--->|
Efficient use of bandwidth!
Pure ALOHA:
- Send whenever you have data
- Collision? Wait random time, resend
- Efficiency: 18.4%
Slotted ALOHA:
- Send only at slot boundaries
- Efficiency: 36.8% (double!)
Carrier Sense Multiple Access with Collision Detection
1. Listen before sending (Carrier Sense)
2. If busy, wait
3. If idle, send
4. While sending, listen for collision (CD)
5. Collision? Send jam signal, wait random time
Collision Avoidance (can't detect collision in wireless)
1. Listen before sending
2. Send RTS (Request to Send)
3. Receive CTS (Clear to Send)
4. Send data
5. Receive ACK
| Concept | Key Point |
|---|---|
| Frame | Data Link PDU with header and trailer |
| CRC | Most reliable error detection |
| MAC | 48-bit physical address |
| CSMA/CD | Ethernet collision handling |
| CSMA/CA | Wi-Fi collision avoidance |
| Sliding Window | Efficient flow control |
Test your understanding with step-by-step solutions
10 questions · 90s per question
Each question has a 90-second time limit. Unanswered questions will be auto-submitted when time runs out.