Cover
Inizia ora gratuitamente eitf45 -L4- data link layer control functions.pdf
Summary
# Framing and bit stuffing in data link layer
Framing and bit stuffing in data link layer organizes the physical layer's bitstream into frames and ensures data integrity by preventing premature flag detection.
## 1. Framing in the data link layer
### 1.1 Purpose of framing
The physical layer delivers a raw bitstream, which is a continuous sequence of bits. The data link layer's responsibility is to organize this bitstream into discrete units called frames. This framing process is crucial for managing data transmission, error detection, and flow control [4](#page=4).
### 1.2 Why frames?
Frames allow the data link layer to implement mechanisms like sequence numbers (SEQ) and acknowledgments (ACK) for reliable data transfer. They also facilitate error detection using Cyclic Redundancy Check (CRC). Without framing, it would be difficult to delineate individual data units and manage their transmission effectively [4](#page=4).
## 2. Bit stuffing
### 2.1 The need for bit stuffing
Bit stuffing is a technique used to ensure that the data within a frame does not accidentally mimic the frame delimiter (flag). A common flag sequence used to mark the beginning and end of a frame is `01111110`. The problem arises if the actual data payload contains a sequence of six or more consecutive '1's, as this could be misinterpreted by the receiver as the end-of-frame flag, leading to premature frame termination [5](#page=5).
> **Tip:** Bit stuffing is a mechanism to guarantee that the flag sequence does not appear within the payload of a frame, thus maintaining the integrity of frame boundaries.
### 2.2 Bit stuffing mechanism
To prevent the flag sequence from appearing in the payload, a bit stuffing procedure is employed:
* **Sender's action:** When the sender detects five consecutive '1's in the payload, it automatically inserts an extra '0' bit immediately after the fifth '1'. This breaks the sequence of six or more '1's [5](#page=5).
* **Receiver's action:** Upon receiving the data, the receiver performs de-stuffing. If it encounters a '0' bit immediately following five consecutive '1's, it removes that '0' bit. This restores the original data stream [5](#page=5).
#### 2.2.1 Example of bit stuffing
Consider the flag sequence `01111110`. If the payload data contains a sequence like `01111111110` the sender would stuff a '0' after the fifth consecutive '1' [5](#page=5):
Original payload: `01111111110`
Stuffing at the first five 1's: `011111`**`0`**`111110`
Stuffing at the second five 1's: `011111011111`**`0`**`0`
The framed data would then look something like: `01111110` **`01111101111100`** `01111110` [5](#page=5).
The receiver, upon seeing `0111110` followed by a '0', will remove the '0' to get `0111111`. Similarly, when it sees `111110` followed by a '0', it will remove the '0' to get `111111`. This ensures that only the actual frame delimiters are recognized as such [5](#page=5).
---
# Error detection mechanisms
This section details various techniques used to detect errors in transmitted data, ensuring data integrity over communication channels [10](#page=10).
### 2.1 The role of error detection
Error detection mechanisms are fundamental components of link layer protocols. Their primary goal is to ensure that data is assumed to be error-free by higher network layers. Errors, which can manifest as bit errors or burst errors typically occur at the physical layer and are the responsibility of the data link layer to handle. The process involves adding extra bits, through an encoding scheme, to the original data before transmission. The receiver then uses these extra bits to check for errors [6](#page=6) [7](#page=7) [8](#page=8) [9](#page=9).
### 2.2 Error detection schemes
Several methods are employed for error detection, each with varying levels of complexity and effectiveness. The common schemes include the simple parity-check code, checksum, and the Cyclic Redundancy Check (CRC) [10](#page=10).
#### 2.2.1 Simple parity-check code
The simple parity-check code involves adding an extra bit, known as a parity bit, to the dataword. This bit is chosen to make the total number of '1's in the resulting codeword either even (even parity) or odd (odd parity) [11](#page=11).
* **Even Parity:** The parity bit is set to '1' if the number of '1's in the dataword is odd, and '0' if the number of '1's is even, ensuring an even total count of '1's in the codeword.
* **Odd Parity:** The parity bit is set to '1' if the number of '1's in the dataword is even, and '0' if the number of '1's is odd, ensuring an odd total count of '1's in the codeword.
A significant limitation of this method is that it can only detect an odd number of errors. If an even number of bit errors occur, the parity remains unchanged, and the error goes undetected [11](#page=11).
> **Tip:** While simple to implement, the parity-check code is not very robust. It's useful for detecting single-bit errors but fails for common scenarios like burst errors or even numbers of bit flips.
#### 2.2.2 Checksum
The checksum is another error detection technique used by several Internet protocols. The concept involves treating the data to be transmitted as a sequence of numbers. These numbers are then added together to produce a checksum value, which is appended to the data. The receiver performs the same addition on the received data. If the calculated checksum matches the received checksum, the data is considered error-free [14](#page=14).
> **Example:** If a bit sequence is to be protected with a 4-bit checksum, it is typically divided into segments. These segments are then treated as binary numbers and summed up. The checksum is derived from this sum, often by taking the one's complement of the sum.
#### 2.2.3 Cyclic Redundancy Check (CRC)
Cyclic Redundancy Check (CRC) is a more robust and widely used error detection mechanism. It relies on polynomial division for its operation [15](#page=15).
##### 2.2.3.1 Polynomial representation
In CRC, both the dataword and the generator are represented as polynomials.
* **Dataword (k bits):** Represented by a polynomial $d(x)$ of degree $k-1$ [16](#page=16).
* **Generator (m bits):** Represented by a polynomial $g(x)$ of degree $m-1$. This generator polynomial is predefined and shared between the sender and receiver [15](#page=15) [16](#page=16).
##### 2.2.3.2 The CRC principle
The objective of CRC is to find a remainder polynomial $r(x)$ such that when the data polynomial $d(x)$ is shifted left by $m-1$ positions (effectively multiplying by $x^{m-1}$) and the remainder $r(x)$ is added, the resulting codeword polynomial $c(x)$ is perfectly divisible by the generator polynomial $g(x)$ without any remainder [17](#page=17).
The formula is:
$$c(x) = d(x) \cdot x^{m-1} + r(x)$$
This implies that:
$$REM[c(x) / g(x)] = 0$$
The remainder polynomial $r(x)$ will have a degree of $m-2$ or less, meaning the CRC itself will consist of $m-1$ bits [17](#page=17).
> **Example:** For a dataword $1001$ (k=4), represented by $d(x) = x^3+1$, and a generator $1011$ (m=4), represented by $g(x) = x^3+x+1$. We want to find $r(x)$ such that $c(x) = d(x) \cdot x^3 + r(x)$ is divisible by $g(x)$.
>
> This involves polynomial long division.
> $d(x) \cdot x^3 = (x^3+1) \cdot x^3 = x^6 + x^3$.
>
> Performing the division of $x^6 + x^3$ by $x^3+x+1$:
> $x^6 + x^3$ divided by $x^3+x+1$ gives a quotient of $x^3+x$ and a remainder of $x+1$.
> So, $r(x) = x+1$.
>
> The codeword polynomial would be $c(x) = x^6 + x^3 + (x+1) = x^6+x^3+x+1$.
> The CRC bits (remainder) are $011$ (representing $x+1$, degree $1 < m-1=3$). The degree of $r(x)$ is $1$, which is $\leq m-2 = 2$.
> The final codeword would be $1001110$, where $1001$ is the data and $110$ are the CRC bits. Wait, the derivation in the document shows a different remainder. Let's re-evaluate the example based on the document's illustration [19](#page=19).
>
> Document illustration:
> Dataword: $1001$, $d(x) = x^3+1$. Generator: $1011$, $g(x) = x^3+x+1$.
> $d(x) \cdot x^{m-1} = (x^3+1) \cdot x^3 = x^6 + x^3$.
>
> The polynomial division depicted in shows [19](#page=19):
> $1001000$ (which is $d(x) \cdot x^3$)
> XOR with $1011$ (this is the first step of division, equivalent to subtracting $g(x)$ shifted)
> Resulting in $0010$
> Bring down the next bit ($0$) to get $00100$
> XOR with $0000$ (as the leading bit is $0$)
> Resulting in $0100$
> Bring down the next bit ($0$) to get $01000$
> XOR with $1011$ (this is where $g(x)$ is subtracted)
> Resulting in $1110$
> Bring down the last bit ($0$) to get $11100$ (error in transcription, should be $1111$ from the previous step)
> The document illustration for $d(x) \cdot x^3$ has an extra bit. The calculation for $d(x) \cdot x^{m-1}$ is for a $k$-bit dataword and an $m$-bit generator to produce an $(k+m-1)$-bit codeword. So for $k=4$ and $m=4$, we consider $d(x) \cdot x^{4-1} = d(x) \cdot x^3$.
>
> $d(x) = x^3+1$
> $d(x) \cdot x^3 = (x^3+1)x^3 = x^6 + x^3$
>
> Polynomial division of $x^6 + x^3$ by $x^3+x+1$ (using binary arithmetic, XOR operation):
> $1001000$ ($x^6+x^3$)
> $1011$ ($g(x)$ aligned)
> ----- (XOR)
> $0010000$ (bring down next 0)
> $0000$ ($g(x)$ aligned, multiplied by $0$)
> ----- (XOR)
> $010000$ (bring down next 0)
> $1011$ ($g(x)$ aligned, multiplied by $1$, $x \cdot g(x) = x^4+x^2+x$)
> ----- (XOR)
> $110100$ (this calculation seems to be deviating from standard polynomial division, let's stick to the document's visual representation)
>
> Based on the provided diagram the polynomial division of $1001000$ by $1011$ yields a remainder $r(x)$ represented by $110$ [19](#page=19).
>
> Thus, $r(x) = x^2 + x$.
> The codeword $c(x)$ is $d(x) \cdot x^3 + r(x) = (x^3+1)x^3 + (x^2+x) = x^6+x^3+x^2+x$.
> This corresponds to the bit string $1001110$.
> The remainder $110$ has $m-1=3$ bits [17](#page=17).
##### 2.2.3.3 Standard CRC polynomials
Various standard CRC polynomials are defined and used in different communication protocols and standards, such as CRC-8, CRC-16, CRC-32, etc. These polynomials are chosen for their error-detecting capabilities. Some common CRC polynomials are listed in [22](#page=22).
> **Tip:** Understanding the polynomial representation and the division process is key to mastering CRC. It's important to remember that the generator polynomial $g(x)$ must have its highest and lowest order bits set to 1 [22](#page=22).
### 2.3 Error detection in practice
The choice of error detection mechanism depends on factors like the expected error rate, the required level of reliability, and the computational resources available. CRC is generally preferred for its superior error detection capabilities compared to parity checks or simple checksums [11](#page=11) [14](#page=14) [15](#page=15).
---
# Error correction and flow control strategies
This topic explores mechanisms for handling detected errors and managing data transmission rates to prevent receiver overload [23](#page=23) [41](#page=41).
### 3.1 Error correction strategies
When errors are detected in transmitted data, two primary strategies exist for correction: Forward Error Correction (FEC) and retransmission [23](#page=23).
#### 3.1.1 Forward error correction (FEC)
FEC involves sending each bit multiple times and employing a majority decision at the receiver to decode the correct value. This method allows the receiver to correct errors without requiring retransmission from the sender [23](#page=23).
#### 3.1.2 Retransmission
The alternative to FEC is retransmission, where the entire frame containing the detected error is resent. This approach relies on the receiver acknowledging correctly received frames [23](#page=23) [24](#page=24).
### 3.2 Flow control mechanisms
Flow control ensures that a sender does not overwhelm a receiver with data. Key protocols for flow control, often implemented within Automatic Repeat Request (ARQ) schemes, include Stop-and-Wait, Go-back-N, and Selective Repeat [25](#page=25) [30](#page=30) [41](#page=41).
#### 3.2.1 Stop-and-wait ARQ
In the Stop-and-Wait ARQ protocol, the sender transmits a frame and then stops, waiting for an acknowledgment (ACK) from the receiver before sending the next frame. A timer is maintained for the waiting period, and if the ACK is not received within this time, the frame is retransmitted. Sequence numbers are used for frames, and acknowledgments typically indicate the expected next sequence number [26](#page=26).
**Normal operation:** The sender sends a frame, waits for an ACK, and then proceeds to the next frame [27](#page=27).
**Potential issues:**
* **Frame loss:** If a transmitted frame is lost, the sender will time out waiting for an ACK and will retransmit the frame [28](#page=28).
* **ACK loss:** If the ACK for a correctly received frame is lost, the sender will time out and retransmit the frame, even though the receiver already has it. This can lead to duplicate frames at the receiver [29](#page=29).
**Inefficiency:** A significant drawback of Stop-and-Wait is its inefficiency due to frequent waiting periods, which do not keep the communication "pipe" full [30](#page=30).
#### 3.2.2 Sliding window protocols
To address the inefficiency of Stop-and-Wait, sliding window protocols were developed. These protocols aim to keep the communication channel busy by allowing the sender to transmit multiple frames before requiring an acknowledgment. The "window" represents the set of frames that can be sent, and its size is crucial [30](#page=30) [31](#page=31).
##### 3.2.2.1 Go-back-N ARQ
Go-back-N ARQ is an improvement that allows the sender to transmit up to 'N' frames without waiting for individual ACKs. The receiver acknowledges frames sequentially. If a frame is lost, the sender will time out or receive a negative acknowledgment, and then it must retransmit the lost frame and all subsequent frames that were sent after it [32](#page=32) [33](#page=33).
**Normal operation:** The sender transmits frames sequentially, and the receiver acknowledges them [32](#page=32).
**Frames lost:** If frame 'k' is lost, the sender will eventually have to retransmit frame 'k' and all frames 'k+1', 'k+2', etc., that were sent [33](#page=33).
**Window size constraint:** For Go-back-N, the window size must be less than $2^m$, where $m$ is the number of bits used for sequence numbers. This constraint helps to avoid ambiguity between old and new frame numbers [37](#page=37).
##### 3.2.2.2 Selective repeat ARQ
Selective Repeat ARQ aims for higher efficiency by avoiding the retransmission of all subsequent frames when a single frame is lost. If a frame is lost, only that specific lost frame is retransmitted. This requires more complexity at the receiver, which needs to buffer out-of-order frames [34](#page=34).
**Efficiency:** Higher efficiency is achieved because unnecessary retransmissions are eliminated [34](#page=34).
**Complexity:** Requires higher receiver complexity to handle out-of-order frame buffering [34](#page=34).
**Window size constraint:** For Selective Repeat, the window size is typically $2^m - 1$, where $m$ is the number of bits for sequence numbers. This allows for unique identification of frames within the window [37](#page=37).
#### 3.2.3 Window size and RTT
The size of the sliding window is directly related to the Round-Trip Time (RTT) of the network. The goal is to allow the sender to transmit frames throughout the RTT period without depleting the window before the first ACK is expected. A larger window size can be used when the RTT is longer, assuming it does not violate the constraints for Go-back-N or Selective Repeat protocols [40](#page=40).
> **Tip:** Understanding the relationship between window size, RTT, and the number of bits for sequence numbers ($m$) is crucial for designing efficient and reliable data link protocols.
> **Example:** If using 3 bits for sequence numbers ($m=3$), the sequence numbers range from 0 to 7. For Go-back-N, the maximum window size is less than $2^3 = 8$, so it could be 7. For Selective Repeat, the maximum window size is $2^3 - 1 = 7$.
---
## Common mistakes to avoid
- Review all topics thoroughly before exams
- Pay attention to formulas and key definitions
- Practice with examples provided in each section
- Don't memorize without understanding the underlying concepts
Glossary
| Term | Definition |
|------|------------|
| Framing | The process by which the link layer organizes the physical layer's bitstream into discrete units called frames, enabling structured data transmission. |
| Bit stuffing | A technique used in data link layer protocols to prevent the occurrence of flag sequences within the data payload by inserting or deleting specific bits, typically a '0' after five consecutive '1's. |
| Error detection | A mechanism employed by the data link layer to identify the presence of errors introduced during data transmission, ensuring that the receiver is aware of corrupted data. |
| Error correction | A mechanism that not only detects but also corrects errors in transmitted data, allowing the receiver to reconstruct the original, uncorrupted data without retransmission. |
| Flow control | A mechanism that manages the rate of data transmission between two nodes to prevent a fast sender from overwhelming a slow receiver, ensuring efficient and reliable communication. |
| Parity-check code | A simple error detection scheme that adds an extra bit (parity bit) to a dataword to make the total number of '1's either even (even parity) or odd (odd parity), capable of detecting an odd number of bit errors. |
| Checksum | An error detection technique that involves summing up blocks of data and transmitting the sum along with the data; the receiver recalculates the sum and compares it to detect errors. |
| Cyclic Redundancy Check (CRC) | A sophisticated error detection algorithm that uses polynomial division to generate a checksum, providing a high probability of detecting burst errors and other common transmission faults. |
| Polynomial representation | A method of representing bit sequences and generator polynomials in error detection schemes like CRC, where bits correspond to coefficients of a polynomial, facilitating mathematical operations. |
| Dataword | The original sequence of bits representing the data to be transmitted. |
| Generator polynomial | A predefined polynomial used in CRC calculations to generate the remainder, which is appended to the dataword to form the codeword. |
| Codeword | The data transmitted after error detection/correction bits have been added to the original dataword. |
| Forward Error Correction (FEC) | An error correction technique where redundant data is added to the original data in such a way that the receiver can detect and correct a certain number of errors without requiring retransmission. |
| Retransmission | The process of resending an entire frame or data block that has been detected as erroneous or lost during transmission. |
| Stop-and-wait ARQ | An Automatic Repeat reQuest protocol where the sender transmits a frame and then waits for an acknowledgment (ACK) from the receiver before sending the next frame, with a timeout mechanism for retransmission. |
| Automatic Repeat Request (ARQ) | A family of error control protocols that use acknowledgments and timeouts to detect and recover from transmission errors. |
| Go-back-N ARQ | An ARQ protocol where the sender can transmit multiple frames before waiting for an ACK. If an error is detected, the sender retransmits the erroneous frame and all subsequent frames. |
| Selective repeat ARQ | An ARQ protocol that is more efficient than Go-back-N, as it only retransmits the specific frames that were detected as erroneous or lost, and the receiver buffers out-of-order frames. |
| Sliding window | A flow control mechanism that allows the sender to transmit multiple frames within a defined window size without waiting for individual ACKs, improving efficiency over stop-and-wait. |
| Round-trip time (RTT) | The total time taken for a signal or data packet to travel from a sender to a receiver and back to the sender. |