Data Link Layer Comprehensive Exercises
Exercise 1: Fundamental Concepts
- Briefly describe the main functions of the data link layer.
Approach: list the five functions of the data link layer and the mechanism behind each one.
Steps:
The main functions of the data link layer are:
- Framing: dividing the bit stream into frames so that they can be managed and checked for errors
- Error control: error detection (parity check, CRC) and error correction (Hamming code)
- Flow control: preventing the sender from transmitting too fast, usually through a sliding window
- Reliable transmission: acknowledgment and retransmission mechanisms
- Medium access control: the rules for accessing a channel shared by multiple stations
Answer: framing, error control, flow control, reliable transmission, and medium access control.
- What is the basic idea behind CRC error detection?
Approach: follow the four stages of a CRC exchange, from sender computation to receiver check.
Steps:
The basic idea of CRC error detection:
- Sender: divide the data polynomial by the generator polynomial modulo 2 and append the remainder to the data as the check code
- Transmission: send the data plus the check code
- Receiver: perform the same modulo-2 division on the received data plus the check code using the same generator polynomial
- Decision: a remainder of 0 means no error; a non-zero remainder means an error occurred
CRC detects both burst errors and random errors, so its detection capability is strong.
Answer: the sender computes the remainder of the data modulo the generator polynomial and appends it; the receiver repeats the division and treats a non-zero remainder as an error.
Exercise 2: Flow Control
- What is the difference between the sliding window protocol and the stop-and-wait protocol?
Approach: compare the two protocols on sending strategy, window size, efficiency, and implementation complexity.
Steps:
The main differences are:
-
Sending strategy:
- Stop-and-wait: sends one frame at a time and waits for the acknowledgment
- Sliding window: may send several frames without waiting for an acknowledgment
-
Window size:
- Stop-and-wait: send window = 1, receive window = 1
- Sliding window: send window > 1, receive window ≥ 1
-
Efficiency:
- Stop-and-wait: low efficiency and low channel utilization
- Sliding window: high efficiency and high channel utilization
-
Complexity:
- Stop-and-wait: simple to implement
- Sliding window: relatively more complex to implement
Answer: stop-and-wait sends one frame and waits, while the sliding window protocol sends several frames within a window and needs only one acknowledgment for the whole batch, which gives it much higher channel utilization.
- What is the main difference between the GBN and SR protocols?
Approach: compare the two protocols on the receive window, the retransmission policy, efficiency, and complexity.
Steps:
The main differences are:
-
Receive window:
- GBN: receive window = 1, frames are accepted only in order
- SR: receive window > 1, out-of-order frames can be buffered
-
Retransmission policy:
- GBN: retransmits the erroneous frame and every frame after it
- SR: retransmits only the erroneous frame
-
Efficiency:
- GBN: may retransmit frames that were already received correctly, so it is less efficient
- SR: retransmits only the erroneous frame, so it is more efficient
-
Complexity:
- GBN: the receiver is simple
- SR: the receiver must buffer frames, which makes the implementation complex
Answer: GBN has a receive window of 1 and retransmits the erroneous frame plus everything after it; SR has a larger receive window and retransmits only the erroneous frame, at the cost of receiver buffering.
Exercise 3: Medium Access Control
- Which medium access control method does Ethernet use, and how does it work?
Approach: name the protocol, then break it into its five steps and the operating sequence they produce.
Steps:
Ethernet uses CSMA/CD (Carrier Sense Multiple Access with Collision Detection).
The basic principle:
- Carrier sense: listen to the channel before transmitting to check whether it is idle
- Multiple access: several stations share the same channel
- Collision detection: keep listening while transmitting to detect collisions
- Collision handling: stop transmitting immediately on detecting a collision and send a jamming signal
- Retransmission: retransmit after a random delay
The operating sequence:
- When a station has data to send, it first listens to the channel
- If the channel is idle, it transmits immediately
- It keeps listening while transmitting
- If a collision is detected, it stops transmitting immediately and sends a jamming signal
- It waits for a random time and then tries again
Answer: Ethernet uses CSMA/CD, which senses the channel before transmitting, detects collisions during transmission, stops and signals on collision, and retransmits after a random backoff.
- What are the main differences between CSMA/CD and CSMA/CA?
Approach: compare the two protocols on collision handling, target environment, operating principle, the hidden terminal problem, and efficiency.
Steps:
The main differences are:
-
How collisions are handled:
- CSMA/CD: handles collisions after detecting them
- CSMA/CA: avoids collisions before they happen
-
Target environment:
- CSMA/CD: wired networks (Ethernet)
- CSMA/CA: wireless networks (Wi-Fi)
-
Operating principle:
- CSMA/CD: detects collisions while transmitting
- CSMA/CA: avoids collisions before transmitting through RTS/CTS
-
The hidden terminal problem:
- CSMA/CD: does not have this problem
- CSMA/CA: solves it with RTS/CTS
-
Efficiency:
- CSMA/CD: efficient in a wired environment
- CSMA/CA: more reliable in a wireless environment
Answer: CSMA/CD detects and handles collisions after transmission begins and suits wired links; CSMA/CA avoids collisions before transmission through RTS/CTS and suits wireless links, where collisions cannot be reliably detected.
Exercise 4: Protocols and Devices
- What are the similarities and differences between the PPP and HDLC protocols?
Approach: group the properties into similarities and differences, with the differences ordered by importance.
Steps:
Similarities:
- Both are data link layer protocols
- Both support point-to-point connections
- Both provide error control functions
Differences:
-
Orientation:
- PPP: byte-oriented
- HDLC: bit-oriented
-
Complexity:
- PPP: simple and easy to implement
- HDLC: complex and powerful
-
Supported connections:
- PPP: mainly point-to-point
- HDLC: point-to-point and multipoint
-
Authentication:
- PPP: supports PAP/CHAP authentication
- HDLC: does not support authentication
-
Network layer protocols:
- PPP: supports multiple network layer protocols
- HDLC: is independent of the network layer protocol
Answer: both are data link layer protocols with point-to-point support and error control; PPP is byte-oriented, simpler, and adds authentication and network layer negotiation, while HDLC is bit-oriented, more complex, and supports multipoint links.
- What is the difference between a switch and a bridge?
Approach: list the shared properties, then the five properties on which they differ.
Steps:
Similarities:
- Both are data link layer devices
- Both forward based on MAC addresses
- Both can connect multiple network segments
Differences:
-
Number of ports:
- Bridge: usually only 2 ports
- Switch: usually many ports (4, 8, 16, 24, and so on)
-
Forwarding method:
- Bridge: store and forward
- Switch: store and forward or cut-through
-
Performance:
- Bridge: forwards more slowly
- Switch: forwards quickly and supports parallel forwarding
-
Features:
- Bridge: basic functions
- Switch: rich features, including VLANs and QoS
-
Application scenarios:
- Bridge: connecting two network segments
- Switch: building the core of a LAN
Answer: a switch is a multi-port bridge that gives each port its own collision domain, forwards in parallel, and adds features such as VLANs and QoS; a bridge is a simple two-port device for joining two segments.
Exercise 5: Comprehensive Application
- In an Ethernet environment, how does CSMA/CD handle a collision?
Approach: walk through the collision handling sequence, then spell out the binary exponential backoff.
Steps:
The steps CSMA/CD follows when a collision occurs:
- Collision detection: keep listening to the channel while transmitting
- Immediate stop: stop transmitting as soon as the collision is detected
- Send a jamming signal: send a jamming signal to notify the other stations that a collision occurred
- Wait a random time: compute the waiting time with the binary exponential backoff algorithm
- Try again: retransmit when the waiting time has elapsed
The binary exponential backoff algorithm:
- 1st collision: wait 0 or 1 slot times
- 2nd collision: wait 0, 1, 2, or 3 slot times
- 3rd collision: wait 0 to 7 slot times
- At most 16 retries, after which the frame is abandoned
Answer: the sender detects the collision, stops immediately, sends a jamming signal, waits a random backoff time drawn from a range that doubles with each collision, and then retransmits.
- Why do wireless networks use CSMA/CA instead of CSMA/CD?
Approach: give the three technical reasons collision detection fails on a wireless link, then explain the RTS/CTS mechanism that replaces it.
Steps:
Why wireless networks use CSMA/CA:
-
Collision detection is difficult:
- wireless signal propagation characteristics are complex
- a collision is hard to detect while transmitting
- the hidden terminal problem
-
Signal characteristics:
- wireless signals attenuate quickly
- the transmit power is limited
- collision detection is hard to implement
-
The hidden terminal problem:
- two stations may not be able to communicate directly
- but both can reach the AP
- CSMA/CA solves this with RTS/CTS
-
The RTS/CTS mechanism:
- the sender first sends an RTS (Request To Send)
- the receiver replies with a CTS (Clear To Send)
- other stations that hear the CTS defer their transmissions
-
Greater reliability:
- avoiding a collision is more effective than detecting it
- the number of retransmissions is reduced
- network efficiency improves
Answer: a wireless transmitter cannot reliably hear a collision because of attenuation, limited transmit power, and hidden terminals, so CSMA/CA avoids collisions in advance with IFS waiting, random backoff, and RTS/CTS instead of detecting them afterwards.
