跳转至

3.0 Data Link Layer

Overview and Position in OSI Model

The Data Link Layer is the second layer in the OSI model, situated above the Physical Layer and below the Network Layer. Its primary responsibility is to get packets from one hop to the next across a single network link. It takes the raw bit stream from the Physical Layer and transforms it into frames.

FunctionPurposeKey Mechanisms
FramingBundle bits into logical units (frames)Flag, Header, Data Payload, Trailer
Flow ControlRegulate transmission rate between sender/receiverReceiver signaling, Window management
Error ControlDetect and correct transmission errorsError detection codes, Retransmissions
Access ControlManage shared medium accessCSMA, Collision detection/avoidance

Framing Details

  • Purpose: Ensure reliable transmission and perform limited error detection/recovery within the link
  • Frame Structure:
  • Flag: Marking the start and end
  • Header: Control information like addresses (MAC addresses)
  • Data Payload: From the upper layer
  • Trailer: Error detection/correction codes
  • Addressing: Uses MAC addresses (Physical Addresses) to identify devices within the local network

Automatic Repeat reQuest (ARQ) Protocols

ARQ protocols handle transmission errors and control flow through acknowledgements and retransmissions.

Protocol Comparison Table

Protocol TypeWindow SizeError HandlingPerformanceComplexity
Stop-and-Wait ARQ1 frameRetransmit on timeout/NAKLow (waiting overhead)Simple
Go-Back-NN framesRetransmit lost frame + all subsequentMedium (bulk retransmission)Medium
Selective RepeatN framesRetransmit only lost framesHigh (selective retransmission)Complex

Stop-and-Wait ARQ

  • Sender transmits one frame and waits for acknowledgement (ACK)
  • Only after receiving positive ACK does sender transmit next frame
  • If frame or ACK is lost/corrupted, sender retransmits after timeout
  • Provides implicit flow control

Sliding Window Protocols

Both Go-Back-N and Selective Repeat allow multiple frames transmission within a "window" before waiting for acknowledgements. They manage synchronization under conditions of premature timeouts, garbled frames, and lost frames.

Go-Back-N Protocol

  • Error Response: Receiver discards lost/erroneous frame AND all subsequent frames
  • Sender Action: Retransmits lost frame and all frames sent after it within current window
  • Window Impact: Larger window = more frames to retransmit on error

Selective Repeat Protocol

  • Error Response: Receiver discards only the specific bad frame, buffers subsequent correct frames
  • Sender Action: Retransmits ONLY the lost frame
  • Window Impact: Larger window = more buffering required at receiver

Performance Calculation Example

Scenario: 1000-byte frames, 1 Mbps link, 10ms propagation delay, 0.1% frame error rate

Stop-and-Wait Efficiency: * Transmission time (Tt) = 1000 × 8 / 1, 000, 000 = 8ms * Round-trip time (RTT) = 2 × 10ms = 20ms * Total time per frame = Tt + RTT = 28ms * Efficiency = Tt / (Tt + RTT) = 8/28 = 28.6%

Go-Back-N with Window Size 7: * Can send 7 frames before waiting for ACK * If error occurs at frame 4, must retransmit frames 4-7 * Efficiency improves but decreases with error rate

Access Control Protocols

These protocols determine how multiple stations access a shared medium without interference.

Protocol Comparison and Evolution

ProtocolEnvironmentCollision StrategyDetection MethodRecovery Mechanism
CSMAAnyListen before transmitCarrier sensingDefer transmission
CSMA/CDWired (Ethernet)Detect during transmissionSimultaneous monitoringStop + random backoff
CSMA/CAWireless (802.11)Avoid before transmissionRTS/CTS control framesBackoff + retry

Protocol Details

Carrier Sense Multiple Access (CSMA)

  • Stations listen (sense carrier) to channel before transmitting
  • If channel busy, defer transmission
  • Limitation: Cannot detect collisions during transmission

CSMA with Collision Detection (CSMA/CD)

  • Usage: Wired Ethernet networks
  • Process: Sense channel → Transmit if free → Simultaneously listen for collisions
  • On Collision: Stop transmitting + back off for random period + reattempt
  • Advantage: Quick collision detection and recovery

CSMA with Collision Avoidance (CSMA/CA)

  • Usage: Wireless networks (IEEE 802.11)
  • Reason: Collision detection difficult in wireless environments
  • Method: Use control frames (RTS/CTS) to avoid collisions before transmitting
  • Process: Back off after busy channel or perceived collision

Collision Domain Analysis Example

Scenario: 10 stations on shared Ethernet segment

Without Switches (Single Collision Domain): * All 10 stations compete for same medium * Higher collision probability as traffic increases * Performance degrades with more active stations

With Switch (Separate Collision Domains): * Each port creates separate collision domain * Station-to-switch links become point-to-point * Eliminates collisions between different ports

Sublayer Organization

SublayerPrimary FunctionsKey Protocols/Standards
Logical Link Control (LLC)Flow control, Error controlStop-and-Wait, Go-Back-N, Selective Repeat
Media Access Control (MAC)Channel access managementCSMA/CD, CSMA/CA, Token Ring

The Data Link Layer is divided into two conceptual sublayers: * Logical Link Control (LLC): Handles flow control and error control functions * Media Access Control (MAC): Manages station access to shared communication channel

Protocol Complexity Levels

Service Type Classification

Complexity LevelDirectionConnectionAcknowledgmentError HandlingUse Cases
Simplex ConnectionlessOne-wayNoneNoneUpper layerSimple sensors, broadcasts
Half-Duplex ConnectionlessTwo-way alternatingNonePer frameTimeout + retransmissionPoint-to-point links
Full-Duplex Connection-OrientedSimultaneous two-wayEstablishedSequence-basedIn-order deliveryReliable data transfer

Detailed Service Descriptions

Simplex Connectionless

  • Data Flow: Only in one direction
  • Acknowledgment: Sender sends frames without waiting for ACKs
  • Error Handling: No error handling by this layer (delegated to upper layers)

Half-Duplex Connectionless (Acknowledged Connectionless)

  • Data Flow: Both directions but only one at a time (half-duplex)
  • Acknowledgment: Each frame is acknowledged
  • Error Handling: Uses timeouts and retransmissions for lost/garbled frames

Full-Duplex Connection-Oriented (Acknowledged Connected Service)

  • Data Flow: Both directions simultaneously (full-duplex)
  • Connection: Logical connection is established
  • Reliability: Frames are numbered and delivered reliably in order

Conceptual Example: University Network Scenario

Problem Setup

A university has 3 buildings connected via Ethernet switches, with wireless access points in each building.

Network Components: * Building A: 50 wired stations + 1 wireless AP (30 wireless clients) * Building B: 30 wired stations + 1 wireless AP (20 wireless clients)
* Building C: 20 wired stations + 1 wireless AP (15 wireless clients)

Wired Network (CSMA/CD): * Each switch port = separate collision domain * No collisions between buildings (switched infrastructure) * Full-duplex links between switches

Wireless Network (CSMA/CA): * Each AP creates one collision domain for its wireless clients * RTS/CTS mechanism for hidden terminal problem * Half-duplex shared medium within each wireless cell

Frame Processing Example:

Station A1 → Station B5:
1. A1 creates frame with MAC addresses (A1_MAC → B5_MAC)
2. Frame sent to Switch A via CSMA/CD
3. Switch A learns A1_MAC location, forwards to Building B
4. Switch B delivers frame to B5 port
5. B5 receives frame, sends ACK back through same path

Performance Calculation: * Wired throughput: Near line rate (minimal collisions) * Wireless throughput: ~50% of nominal rate (CSMA/CA overhead) * Inter-building latency: Switch processing + propagation delay