Data Link Layer
3.1 Framing
The data link layer receives a bit stream and divides it into manageable frames.
Framing methods:
- Byte count: First field specifies frame length. Vulnerable to corrupted count.
- Flag bytes: Special flag byte (
0x7Efor HDLC) marks start/end. Byte stuffing with escape byte (0x7D) prevents ambiguity. - Bit-oriented flags: Flag pattern
01111110. Bit stuffing: insert0after five consecutive1S in the data. - Clock-based: Manchester encoding provides self-clocking and frame boundaries.
3.2 Error Detection and Correction
Error types: Single-bit errors (one bit flipped), burst errors (multiple consecutive bits).
Hamming distance. is the number of bit positions where codewords and differ. The minimum distance determines capability:
- Detect up to errors.
- Correct up to errors.
Hamming code. Adds parity bits to data bits where . Each parity bit Covers positions whose binary representation has a 1 in a specific bit position.
Example (Hamming(7,4)). 4 data bits, 3 parity bits. : detects 2 errors, corrects 1.
Worked Example: Hamming(7,4) Encoding and Error Correction
Encoding. Transmit data bits .
Codeword positions (1-indexed): . Place data bits: position 3 = 1, position 5 = 0, position 6 = 1, position 7 = 1.
Parity bits cover positions whose binary index has a 1 in the corresponding bit:
covers positions with bit 0 set: {1, 3, 5, 7}. covers positions with bit 1 set: {2, 3, 6, 7}. covers positions with bit 2 set: {4, 5, 6, 7}.
Calculate parity bits (even parity):
: positions 1, 3, 5, 7 data at 3, 5, 7 are 1, 0, 1. Sum = 0 (even) .
: positions 2, 3, 6, 7 data at 3, 6, 7 are 1, 1, 1. Sum = 1 (odd) .
: positions 4, 5, 6, 7 data at 5, 6, 7 are 0, 1, 1. Sum = 0 (even) .
Transmitted codeword:
Error correction. Suppose bit 6 is flipped during transmission. Received word:
Compute syndrome bits:
: check positions 1, 3, 5, 7 (even, OK).
: check positions 2, 3, 6, 7 (odd, error).
: check positions 4, 5, 6, 7 (odd, error).
Syndrome = . The error is at position 6. Flip bit 6: Corrected word = .
Answer: The Hamming code detects and corrects the single-bit error at position 6.
Cyclic Redundancy Check (CRC). A polynomial code widely used (Ethernet, Wi-Fi, USB).
- Append zero bits to the message ( = degree of generator polynomial ).
- Divide the augmented message polynomial by using modulo-2 arithmetic.
- Append the remainder (CRC) to the original message.
- Receiver divides by ; zero remainder means no error.
Theorem 3.1. CRC detects all single-bit errors, all double-bit errors (if has factor ), all odd-numbered errors, and all burst errors of length .
Worked Example: CRC Polynomial Division
Compute the CRC for message 110100 using generator (binary 1011Degree ).
Step 1: Append zero bits augmented message: 110100000.
Step 2: Perform modulo-2 (XOR) polynomial division.
Division steps:
. Multiply: . Subtract (XOR): .
. Multiply: . Subtract: .
. Multiply: . Subtract: .
. Multiply: . Subtract: .
Degree of (which is 2) is less than degree of (which is 3). Stop.
Remainder: = binary 100.
Step 3: Append remainder to original message. Transmitted codeword: 110100100.
Verification. The receiver divides 110100100 by 1011. Since was chosen as the remainder, So the division yields remainder 0, Confirming no error.
3.3 MAC Protocols
ALOHA. Transmit whenever ready; if collision, wait random time and retransmit.
- Pure ALOHA: Throughput Maximum at : .
- Slotted ALOHA: Time divided into slots; transmit at slot boundary. Maximum at : .
CSMA (Carrier Sense Multiple Access). Listen before transmitting.
- 1-persistent: If busy, wait; transmit immediately when idle. High collision probability.
- Non-persistent: If busy, wait random time before sensing again. Lower collision, higher delay.
- p-persistent: If busy, wait until idle, then transmit with probability .
CSMA/CD (Collision Detection). Used in wired Ethernet (802.3). Transmit and listen simultaneously; If collision detected, send jam signal and wait random backoff.
- Binary exponential backoff: After -th collision, choose random and wait bit times.
- Minimum frame size: Must be at least where is the round-trip propagation delay. For 10 Mbps Ethernet with : minimum frame = 64 bytes.
CSMA/CD collision analysis. The sender must still be transmitting when a collision signal returns From the farthest point on the network. The worst-case round-trip propagation time is Where ( is the maximum cable length, is the signal propagation speed, m/s in copper). The minimum frame size is therefore:
Where is the data rate.
Worked Example: CSMA/CD Minimum Frame Size
A 100 Mbps Ethernet network uses a maximum cable length of 2 km. Signal propagation speed is m/s. Calculate the minimum frame size.
One-way propagation delay:
Worst case: collision occurs at the far end, signal must travel back. Total time is .
The sender must still be transmitting after :
Answer: The minimum frame size is 250 bytes (2000 bits). Any frame shorter than this risks an Undetected collision.
CSMA/CA (Collision Avoidance). Used in wireless (802.11). Cannot detect collisions while Transmitting (half-duplex radio). Uses RTS/CTS handshake and inter-frame spacing (IFS).
Wi-Fi (IEEE 802.11). Wireless LAN standards operating in the 2.4 GHz, 5 GHz, and 6 GHz bands.
| Standard | Frequency | Max PHY Rate | Channel Width |
|---|---|---|---|
| 802.11a | 5 GHz | 54 Mbps | 20 MHz |
| 802.11b | 2.4 GHz | 11 Mbps | 22 MHz |
| 802.11g | 2.4 GHz | 54 Mbps | 20 MHz |
| 802.11n | 2.4/5 GHz | 600 Mbps | 20/40 MHz |
| 802.11ac | 5 GHz | 6.93 Gbps | 20-160 MHz |
| 802.11ax | 2.4/5/6 | 9.6 Gbps | 20-160 MHz |
Key 802.11 mechanisms:
- DCF (Distributed Coordination Function): CSMA/CA with random backoff. IFS priorities: SIFS (shortest, for ACKs/CTS), PIFS (PCF), DIFS (standard data), EIFS (after error).
- RTS/CTS: Sender sends Request To Send, receiver replies with Clear To Send. Reduces hidden terminal problem.
- RTS/CTS pseudocode:
void wifi_send(frame *f) { while (channel_busy()) wait(DIFS); send_RTS(); wait_for_CTS(timeout); if (received_CTS()) { wait(SIFS); send_data(f); wait(SIFS); wait_for_ACK(timeout); if (!received_ACK()) { backoff = choose_random(0, 2^min(n,10) - 1) * slot_time; wait(backoff); retry_count++; } } else { backoff = choose_random(0, 2^min(n,10) - 1) * slot_time; wait(backoff); }}- MIMO: Multiple-Input Multiple-Output. Uses multiple antennas for spatial multiplexing (simultaneous streams) and diversity (reliability). 802.11n supports up to 4x4 MIMO.
- OFDM/OFDMA: Orthogonal Frequency-Division Multiplexing divides the channel into subcarriers. OFDMA (802.11ax) allows scheduling different clients on different subcarriers simultaneously.
- BSS (Basic Service Set): An access point (AP) and its associated stations. ESS (Extended Service Set): multiple BSSs connected by a distribution system.
3.4 Ethernet (IEEE 802.3)
Frame format:
| Field | Size | Description |
|---|---|---|
| Preamble | 7 bytes | Alternating 1s and 0s for sync |
| SFD | 1 byte | Start of frame delimiter (10101011) |
| Dest MAC | 6 bytes | Destination MAC address |
| Src MAC | 6 bytes | Source MAC address |
| Type/Len | 2 bytes | EtherType or frame length |
| Payload | 46-1500 B | Data |
| FCS | 4 bytes | Frame check sequence (CRC-32) |
MAC address: 48-bit globally unique address. First 24 bits: OUI (organisation). Last 24 bits: Device-specific. Broadcast: FF:FF:FF:FF:FF:FF. Multicast: least significant bit of the first Octet is 1.
Ethernet evolution:
| Standard | Speed | Medium | Max Segment |
|---|---|---|---|
| 10BASE-T | 10 Mbps | Cat3+ UTP | 100 m |
| 100BASE-TX | 100 Mbps | Cat5+ UTP | 100 m |
| 1000BASE-T | 1 Gbps | Cat5e+ UTP | 100 m |
| 10GBASE-T | 10 Gbps | Cat6a+ UTP | 100 m |
| 10GBASE-SR | 10 Gbps | Multi-mode fibre | 26-300 m |
| 10GBASE-LR | 10 Gbps | Single-mode fibre | 10 km |
| 100GBASE-SR4 | 100 Gbps | Multi-mode fibre | 70-100 m |
| 400GBASE-DR4 | 400 Gbps | Single-mode fibre | 500 m |
Theorem 3.3 (CSMA/CD efficiency). The maximum efficiency of CSMA/CD is:
Where is the ratio of propagation delay to frame transmission time.
Proof. In the worst case, a collision wastes time and one frame transmission time . The useful time per cycle is . The total cycle time is in the worst case, but On average (with the binary exponential backoff), the effective overhead is approximately . Thus .
When (large frames or short distances), efficiency approaches 1. When approaches 1 (short frames or long distances), efficiency drops significantly. This is why minimum frame sizes Are imposed.
3.5 VLANs
A Virtual LAN (VLAN) logically segments a physical LAN into separate broadcast domains at layer 2, Without requiring separate physical infrastructure.
802.1Q frame tagging. A 4-byte tag is inserted after the source MAC address:
| Field | Size | Description |
|---|---|---|
| TPID | 16 bits | Tag Protocol Identifier (0x8100) |
| PCP | 3 bits | Priority Code Point (802.1p) |
| DEI | 1 bit | Drop Eligible Indicator |
| VLAN ID (VID) | 12 bits | VLAN identifier (1-4094) |
Trunking. Links between switches that carry traffic for multiple VLANs. Frames are tagged with Their VLAN ID on trunk links.
Benefits: Security (isolation between VLANs), broadcast containment, flexible network management, Reduced cost (no need for separate switches per segment).
3.6 Switching
Circuit switching. A dedicated path is established for the entire duration. Used in traditional Telephone networks. Constant bandwidth but inefficient for bursty data.
Packet switching. Data divided into packets, each routed independently.
- Datagram: Each packet routed independently (IP). No setup; may arrive out of order.
- Virtual circuit: Logical path established before data transfer (ATM, MPLS). Ordered delivery.
Theorem 3.2. Packet switching achieves higher utilisation than circuit switching for bursty Traffic.
Proof. Circuit switching reserves the peak rate per connection. Packet switching uses statistical Multiplexing: the sum of peak rates can exceed link capacity as long as the average aggregate rate Does not.
Switch forwarding methods. A layer-2 switch can forward frames using two strategies:
| Aspect | Store-and-Forward | Cut-Through |
|---|---|---|
| Operation | Receives entire frame first | Reads destination MAC only |
| Latency | per hop | per hop |
| Error detection | Can check FCS before forward | Cannot check FCS |
| Memory requirement | Must buffer full frame | Only needs header buffer |
| Use case | General-purpose switching | Low-latency environments |
Where is the full frame length, is the header length (14 bytes for Ethernet), is the Link rate, and is the propagation delay.
For a path through switches:
\mathrm{Store}\mathrm{-and\mathrm}{-forward\;latency} = n \cdot \frac{L}{R} + d_{\mathrm{total}}
\mathrm{Cut}\mathrm{-through}\;latency} = \frac{L}{R} + (n-1) \cdot \frac{L_h}{R} + d_{\mathrm{total}
Worked Example: Switching Latency Comparison
A 1500-byte frame traverses 3 store-and-forward switches on 1 Gbps links. Each link has 5 S Propagation delay.
Store-and-forward:
Cut-through:
Answer: Cut-through saves approximately 23.8 S (47% reduction) for this scenario, but it Cannot detect corrupted frames before forwarding them.