26 10 2024
26 10 2024
Error detection and correction in computer networking are essential processes used to ensure
the integrity of data transmitted over a network. When data is transmitted from one device to
another, it may get corrupted due to various reasons like noise, interference, or signal
attenuation. Error detection and correction mechanisms help in identifying and, if possible,
fixing these errors.
1. Error Detection
Error detection refers to identifying errors in the transmitted data. The receiver needs to check
whether the received data is correct or corrupted during transmission. Here are some common
methods used for error detection:
A. Parity Check
Single Parity Check: Adds a parity bit (either 0 or 1) to the data. The parity bit ensures that the
total number of 1s in the data is either even (even parity) or odd (odd parity). If the number of
1s doesn't match the expected parity, an error is detected.
Two-Dimensional Parity Check: Data is arranged in a grid, and both row-wise and column-wise
parity bits are calculated. This method helps in detecting and locating the error in two
dimensions.
CRC is widely used in Ethernet, wireless networks, and many other communication protocols
due to its strong error detection capability.
C. Checksum
Checksum: Involves adding the binary values of data segments, often using modular arithmetic,
and appending the result (the checksum) to the data. The receiver recomputes the checksum
and compares it with the transmitted checksum to detect errors. It’s used in IP, TCP, and UDP.
Hamming codes add extra redundant bits to the data. These bits are placed in positions such
that if an error occurs, it can be detected and, in some cases, corrected.
2. Error Correction
Error correction not only detects errors but also attempts to correct them without needing
retransmission. Two main techniques are used:
Hamming Code: Hamming codes are used for single-bit error correction. For example, if an
error occurs in a single bit, the Hamming code can locate the exact bit and correct it.
Reed-Solomon Codes: Commonly used in CDs, DVDs, and wireless communication. These codes
are capable of correcting burst errors (errors affecting consecutive bits or bytes).
ARQ uses acknowledgments and timeouts to ensure data is transmitted correctly. If an error is
detected, the receiver requests a retransmission. There are three types of ARQ protocols:
Stop-and-Wait ARQ: The sender sends a frame and waits for an acknowledgment. If an error is
detected, the frame is retransmitted.
Go-Back-N ARQ: The sender can transmit several frames before needing an acknowledgment,
but if an error is detected in one frame, all subsequent frames are retransmitted.
Selective Repeat ARQ: Only the erroneous frames are retransmitted, not the entire sequence,
which improves efficiency compared to Go-Back-N.
3. Hybrid ARQ
Hybrid ARQ combines both ARQ and FEC. If an error is detected and cannot be corrected by FEC,
ARQ requests a retransmission. This approach is used in technologies like LTE and Wi-Fi to
improve data integrity while minimizing retransmissions.
Wireless Networks: FEC techniques like Reed-Solomon codes are used to handle noise and
interference.
Internet Protocols: TCP uses checksums for error detection, while ARQ handles retransmissions
in case of error detection.
Conclusion
Error detection and correction techniques are vital to ensuring reliable data communication
across networks. Detection methods like parity checks and CRC efficiently spot errors, while
correction techniques like FEC and ARQ enhance data reliability by fixing errors or triggering
retransmissions. Together, these mechanisms form the backbone of modern networking to
maintain data integrity.
-----------------------------------------+++------------+--+++------+------------------------
CRC
CRC works by treating the data as a large binary number. The transmitter performs a binary
division of the data by a predetermined polynomial (generator) and appends the remainder
(called the CRC checksum) to the end of the data. The receiver performs the same division and
checks whether the remainder matches the transmitted CRC. If the remainders differ, it
indicates that an error has occurred.
A specific binary number (often called the generator polynomial) is chosen. It is agreed upon by
both the sender and receiver.
The original data bits are augmented by appending n zero bits to the end of the data, where n is
the degree of the generator polynomial. These zeros will later be replaced by the CRC checksum.
3. Binary Division:
The sender divides the augmented data by the generator polynomial using binary division (XOR
operations are used instead of actual division). The remainder of this division is the CRC
checksum.
The remainder (CRC checksum) is appended to the original data, and this entire message is
transmitted.
5. Receiver Check:
The receiver receives the data with the CRC checksum and performs the same binary division
using the same generator polynomial.
If the remainder after this division is zero, the transmission is assumed to be error-free. If not,
an error is detected.
Let's say we have a 7-bit message: 1101011, and we use a generator polynomial: 1011 (degree
3).
1. Step 1 (Augment Data): Add three zeros to the message (same as the degree of the
polynomial).
1101011000
2. Step 2 (Binary Division): Divide the message by the polynomial using XOR.
1101011000 ÷ 1011
After performing the binary division, you get a remainder, say 101. This remainder is the CRC
checksum.
3. Step 3 (Transmit Data): The original message 1101011 is transmitted along with the CRC
checksum, making the final transmitted message:
1101011101
4. Step 4 (Receiver Validation): The receiver checks by dividing the received message
(1101011101) by the same polynomial (1011). If the remainder is zero, the data is error-free.
Benefits of CRC:
Highly Effective: CRC can detect burst errors, which are common in data communication,
making it more robust than simple error-detection methods like parity checks.
Fast Calculation: The division process uses bitwise XOR operations, which are computationally
efficient.
Widely Used: CRC is used in many protocols, including Ethernet, USB, Wi-Fi, and digital
communication systems.
Types of CRC:
3. CRC-32: A 32-bit polynomial, widely used in Ethernet, ZIP files, and many other protocols.
Limitations of CRC:
No Correction: CRC can only detect errors but cannot correct them.
Not Perfect: While CRC is highly reliable, it is not infallible. For example, it might fail to detect
errors in rare cases where the error pattern aligns with the polynomial.
Conclusion:
CRC is a crucial tool in networking and data integrity checks. It’s an efficient method for
detecting errors, especially for large blocks of data. Its simplicity and speed make it highly
effective for detecting common errors in data transmission, though it does not correct them.
------------------------------------++++++++++++------------------------------++++---
Hamming Code
Hamming Code is an error-detection and error-correction technique used to ensure reliable
data transmission over noisy communication channels. It can detect up to two-bit errors and
can correct single-bit errors. Developed by Richard Hamming in the 1950s, it adds redundant
bits (called parity bits) to data to enable error correction.
2. Parity Bits: Extra bits added to the data to enable error detection and correction. The number
and positions of parity bits depend on the size of the data block.
3. Error Correction: Hamming codes are designed to identify and correct single-bit errors in the
transmitted data.
Hamming codes use a specific arrangement of data and parity bits. The parity bits are
positioned at certain locations to cover specific groups of data bits.
For a data block of size m, the number of parity bits, r, is calculated such that the following
condition holds:
2^r \geq m + r + 1
Each parity bit checks the values of specific data bits. The parity bit is calculated such that the
sum of the bits it checks (including itself) must be even (in case of even parity) or odd (in case of
odd parity).
If the received data has been corrupted, the parity bits help to pinpoint the exact position of
the error by performing an exclusive-OR operation between the expected and received values.
The binary value formed by the error parity check indicates the position of the erroneous bit.
Suppose we want to encode a 4-bit message 1011 using Hamming code. We need to find the
number and placement of parity bits.
2^r \geq m + r + 1
We insert the parity bits at positions that are powers of 2: positions 1, 2, and 4.
So, the data and parity bits will be positioned like this:
___1_011
Parity bit at position 1 (P1): This covers positions 1, 3, 5, 7 (all bits whose binary representation
includes a 1 in the least significant bit).
P1 = (P1 \oplus D3 \oplus D5 \oplus D7) = (P1 \oplus 1 \oplus 0 \oplus 1) = 0
P1 P2 D3 P4 D5 D6 D7
0 1 1 0 0 1 1
When the receiver gets the message, it checks the parity bits.
1. Error Detection: If there is an error in transmission, the receiver calculates the parity bits and
compares them with the received ones. If the parity bits don't match, an error is detected.
2. Error Correction: If a single-bit error is found, the parity bits form a binary number that
points to the exact position of the erroneous bit, which can then be flipped to correct the error.
Let’s assume the receiver receives the message 0100011 (with a single-bit error in position 2).
Single-Bit Error Correction: Can correct single-bit errors without needing retransmission.
Efficient: Requires relatively few additional bits compared to the original data size, making it
efficient for small blocks of data.
Limitations:
Limited Error Correction: Can only correct single-bit errors; cannot correct two-bit errors,
though it can detect them.
Inefficient for Large Data: For large blocks of data, more efficient error-correcting codes like
Reed-Solomon or BCH codes are often preferred.
Conclusion:
Hamming Code is a fundamental technique for error correction in digital communication
systems, capable of detecting and correcting single-bit errors efficiently. It’s widely used in
memory systems (like ECC RAM) and simple communication protocols where basic error
correction is needed.