0% found this document useful (0 votes)
8 views

Module 2

Uploaded by

jatt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Module 2

Uploaded by

jatt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Module 2: Data Link Layer and Medium Access Sub-Layer

The Data Link Layer (Layer 2) is a critical component in ensuring reliable communication over a
physical link. This layer takes care of error detection and correction, flow control, and access to the
shared medium. The Medium Access Control (MAC) sub-layer is the part of the Data Link Layer
responsible for managing how data packets are transferred between devices in a network, especially
in environments where many devices share the same communication channel.

The topics we will explore in depth include error detection and correction, flow control and error
control protocols, and multiple access protocols. These protocols work together to ensure efficient,
reliable communication on a network.

1. Error Detection and Error Correction

Error Detection is essential because data can be corrupted due to noise, interference, or other
factors while being transmitted over a communication medium. Error Correction helps ensure that
even when errors occur, they can be identified and fixed without needing retransmission, increasing
efficiency.

1.1 Fundamentals of Error Detection and Error Correction

Errors can occur in data transmission in the form of bit errors or burst errors. These errors may be
caused by various factors, including signal attenuation, electrical interference, or physical media
issues. The fundamental goal of error detection is to identify whether the received data is the same
as what was sent.

 Error detection mechanisms include parity bits, checksums, and Cyclic Redundancy Check
(CRC).

 Error correction involves adding redundancy through various coding techniques to recover
the original data even if some bits are corrupted during transmission.

1.2 Block Coding

Block coding involves grouping data into fixed-length blocks and adding extra bits to these blocks to
detect or correct errors. Block codes use redundancy, which allows the receiver to detect or correct
errors without needing retransmissions.

Example: Hamming Code (7,4) A typical block code is the Hamming (7,4) code, which encodes 4 bits
of data into 7 bits by adding 3 parity bits.

For example:

 Data to be transmitted: 1011

 The sender encodes this data by adding 3 parity bits:

o The encoded data is 1011011.

The receiver checks the parity of the bits when it receives the data and can determine whether any
errors have occurred based on these checks.

 Error detection: The receiver calculates the parity of the received 7-bit sequence. If the
parity doesn't match, the receiver knows that an error has occurred.
 Error correction: The Hamming distance (the number of differing bits between two
codewords) helps to identify and correct errors. The Hamming distance for the Hamming
(7,4) code is 3, meaning it can detect 2-bit errors and correct 1-bit errors.

1.3 Cyclic Redundancy Check (CRC)

CRC is a powerful error detection technique that can detect burst errors, which are groups of errors
that affect several consecutive bits. CRC uses polynomial division to generate a checksum, which is
appended to the data before transmission. The receiver performs the same polynomial division and
checks the result to determine if the data was corrupted.

Example: Suppose a sender wants to transmit the data 1101011011 using a CRC polynomial 1011.
The sender divides the data by the polynomial, gets a remainder (checksum), and appends this
remainder to the original data before sending it. When the receiver gets the data, it divides the
received data by the same polynomial. If there is no remainder, the data is considered error-free.

2. Flow Control and Error Control Protocols

Flow Control ensures that data is transmitted at a rate that the receiver can handle. Error Control
ensures that the data sent is reliable and correct. Both of these mechanisms prevent data loss and
inefficient transmission.

2.1 Stop-and-Wait Protocol

In the Stop-and-Wait protocol, after the sender sends one frame, it waits for an acknowledgment
(ACK) before sending the next frame. This ensures that frames are received correctly, but it is
inefficient because the sender has to wait for an acknowledgment after each frame, leading to
potential idle times.

Example:

 Sender sends Frame 1 → waits for ACK

 If Receiver gets Frame 1 correctly, it sends back an ACK.

 If Receiver does not get the frame or if an error is detected, it requests retransmission.

While simple, this protocol is inefficient for high-latency networks because the sender cannot send
the next frame until it receives an acknowledgment.

2.2 Sliding Window Protocol

The Sliding Window Protocol overcomes the limitations of the Stop-and-Wait protocol by allowing
the sender to transmit multiple frames before waiting for an acknowledgment. The sender can send
several frames as long as the number of unacknowledged frames is within the window size.

There are two variations of the Sliding Window Protocol:

 Go-Back-N ARQ: The sender can send multiple frames but must retransmit all frames starting
from the first unacknowledged one if an error occurs.

Example:

 Sender sends frames 1, 2, and 3.


 If Frame 2 is lost, the receiver will acknowledge Frame 1 but not Frame 2.

 The sender will go back and retransmit Frame 2 and all subsequent frames (Frame 3).

 Selective Repeat ARQ: Only the lost or corrupted frame is retransmitted, making this
protocol more efficient than Go-Back-N.

Example:

 Sender sends frames 1, 2, 3, and 4.

 Receiver acknowledges frames 1 and 2 but reports an error in Frame 3.

 The sender retransmits only Frame 3, avoiding the need to resend Frame 4.

2.3 Piggybacking

Piggybacking allows devices to send acknowledgments along with data in the same frame, reducing
the number of frames needed for communication and improving efficiency. This is particularly useful
in full-duplex communication systems, where both devices can send and receive data simultaneously.

Example:

 Device A sends data Frame 1.

 Device B receives Frame 1 and wants to send data back.

 Instead of sending an ACK in one frame and data in another, Device B sends both the data
and the acknowledgment for Frame 1 in the same frame.

3. Multiple Access Protocols

Multiple Access Protocols are essential for managing how devices share the same communication
medium, ensuring that multiple devices can communicate without excessive collisions.

3.1 Pure ALOHA

ALOHA is a simple protocol for random access in which devices transmit at will, without any regard
for other transmissions. If a collision occurs, the device waits for a random amount of time before
retrying.

 Pure ALOHA has a very low efficiency, approximately 18.4%, because the devices don't listen
for interference and will send data regardless of what others are doing.

Example:

 Device 1 sends a frame at time t.

 Device 2 sends a frame at time t + 0.5. A collision occurs.

 Both devices wait for a random backoff period and then resend the frame.

3.2 Slotted ALOHA


Slotted ALOHA improves upon Pure ALOHA by dividing time into equal-sized slots, where each
device can only transmit at the beginning of a time slot. This reduces the probability of collision,
improving the system's efficiency to about 36.8%.

Example:

 Device 1 transmits at the start of Slot 1.

 Device 2 waits for Slot 2 before transmitting.

 This reduces the likelihood of both devices transmitting at the same time and causing a
collision.

3.3 Carrier Sense Multiple Access with Collision Detection (CSMA/CD)

CSMA/CD is a protocol used in Ethernet networks to detect and manage collisions. Before
transmitting, devices listen to the channel. If the channel is idle, they begin transmission. If a collision
occurs, both devices stop transmitting, wait for a random period, and retransmit.

Example:

 Device 1 senses the channel is idle and begins transmitting.

 Device 2 also senses the channel is idle and begins transmitting simultaneously.

 Both devices detect the collision, stop transmitting, wait for a random backoff period, and
then retransmit.

3.4 Carrier Sense Multiple Access with Collision Avoidance (CSMA/CA)

In CSMA/CA, used in wireless networks (like Wi-Fi), the devices avoid collisions by sending a Request
to Send (RTS) message before transmitting data. If no one else is transmitting, the receiver responds
with a Clear to Send (CTS) message, allowing the sender to transmit.

Example:

 Device A sends an RTS to Device B, asking if the channel is clear.

 Device B responds with a CTS if it is clear.

 Device A then sends the data.

Conclusion

The Data Link Layer and Medium Access Sub-Layer are foundational in ensuring reliable and efficient
communication between devices in a network. Error detection and correction ensure that data
remains intact during transmission, while flow control and error control protocols manage the
smooth delivery of data. Multiple access protocols like ALOHA, CSMA/CD, and CSMA/CA enable
devices to share a common medium without excessive collisions.

Through various error detection codes (like Hamming codes and CRC), flow control protocols (like
Stop-and-Wait and Sliding Window), and multiple access techniques, the system efficiently handles
different types of data traffic, ensuring reliability in increasingly complex communication
environments.
How Linear Block Codes Work

1. Message Block:

o The input data is divided into blocks of kkk-bits, called the message.

2. Codeword Generation:

o Each kkk-bit message is mapped to an nnn-bit codeword (n>kn > kn>k) by


multiplying the message vector u\mathbf{u}u with a generator matrix G\
mathbf{G}G.

o Codeword c=u⋅G\mathbf{c} = \mathbf{u} \cdot \mathbf{G}c=u⋅G, where operations


are performed in mod 2 arithmetic (binary addition/multiplication).

3. Redundancy:

o The extra n−kn - kn−k bits in the codeword are redundant bits added to detect
and/or correct errors.

4. Error Detection/Correction:

o At the receiver, the received codeword r\mathbf{r}r is checked using a parity-check


matrix H\mathbf{H}H: s=r⋅HT\mathbf{s} = \mathbf{r} \cdot \mathbf{H}^Ts=r⋅HT

 s\mathbf{s}s is called the syndrome.

 If s=0\mathbf{s} = \mathbf{0}s=0, the codeword is valid.

 If s≠0\mathbf{s} \neq \mathbf{0}s=0, errors are detected, and the code can
correct them (depending on the type of code).

Hamming Codes

Hamming codes are a special type of linear block code designed for single-bit error correction and
double-bit error detection.

How Hamming Codes Work

1. Parameters:

o A Hamming code is defined by (n,k)(n, k)(n,k), where:

 n=2m−1n = 2^m - 1n=2m−1: Total bits (data + parity).

 k=n−mk = n - mk=n−m: Data bits.

 mmm: Number of parity bits.

Example: For m=3m = 3m=3,

o n=7n = 7n=7, k=4k = 4k=4: A (7,4)(7, 4)(7,4) Hamming code.


2. Parity Bit Placement:

o Parity bits are placed at positions that are powers of 2: 1,2,4,…1, 2, 4, \dots1,2,4,….

o Data bits occupy the remaining positions.

Example: For a (7,4)(7, 4)(7,4) code:

o Bits are arranged as: P1,P2,D1,P4,D2,D3,D4P_1, P_2, D_1, P_4, D_2, D_3, D_4P1,P2
,D1,P4,D2,D3,D4, where PiP_iPi are parity bits, and DiD_iDi are data bits.

3. Encoding:

o The parity bits are calculated to ensure that each data bit is included in a unique set
of parity equations. Each parity bit checks certain positions based on binary
representation.

o Example:

 P1P_1P1: Covers positions 1,3,5,71, 3, 5, 71,3,5,7.

 P2P_2P2: Covers positions 2,3,6,72, 3, 6, 72,3,6,7.

 P4P_4P4: Covers positions 4,5,6,74, 5, 6, 74,5,6,7.

4. Decoding and Error Correction:

o At the receiver, the codeword is checked using parity equations.

o The syndrome is calculated, which identifies the position of a single-bit error (if any).

 If syndrome=0\text{syndrome} = 0syndrome=0: No error.

 If syndrome≠0\text{syndrome} \neq 0syndrome=0: The binary value of the


syndrome gives the position of the erroneous bit, which can then be flipped
to correct the error.

Example of Hamming Code

Encoding:

1. Data: D1=1,D2=0,D3=1,D4=1D_1 = 1, D_2 = 0, D_3 = 1, D_4 = 1D1=1,D2=0,D3=1,D4=1 (4


bits).

2. Codeword: P1,P2,D1,P4,D2,D3,D4P_1, P_2, D_1, P_4, D_2, D_3, D_4P1,P2,D1,P4,D2,D3,D4


(7 bits).

3. Calculate parity bits:

o P1=D1⊕D2⊕D4=1⊕0⊕1=0P_1 = D_1 \oplus D_2 \oplus D_4 = 1 \oplus 0 \oplus 1 =


0P1=D1⊕D2⊕D4=1⊕0⊕1=0.
o P2=D1⊕D3⊕D4=1⊕1⊕1=1P_2 = D_1 \oplus D_3 \oplus D_4 = 1 \oplus 1 \oplus 1 =
1P2=D1⊕D3⊕D4=1⊕1⊕1=1.

o P4=D2⊕D3⊕D4=0⊕1⊕1=0P_4 = D_2 \oplus D_3 \oplus D_4 = 0 \oplus 1 \oplus 1 =


0P4=D2⊕D3⊕D4=0⊕1⊕1=0.

4. Encoded Codeword: 0,1,1,0,0,1,10, 1, 1, 0, 0, 1, 10,1,1,0,0,1,1.

Decoding:

1. Received Codeword: 0,1,1,0,0,1,00, 1, 1, 0, 0, 1, 00,1,1,0,0,1,0 (error in the last bit).

2. Calculate syndrome:

o S1=P1⊕D1⊕D2⊕D4=0⊕1⊕0⊕1=0S_1 = P_1 \oplus D_1 \oplus D_2 \oplus D_4 = 0 \


oplus 1 \oplus 0 \oplus 1 = 0S1=P1⊕D1⊕D2⊕D4=0⊕1⊕0⊕1=0.

o S2=P2⊕D1⊕D3⊕D4=1⊕1⊕1⊕1=0S_2 = P_2 \oplus D_1 \oplus D_3 \oplus D_4 = 1 \


oplus 1 \oplus 1 \oplus 1 = 0S2=P2⊕D1⊕D3⊕D4=1⊕1⊕1⊕1=0.

o S4=P4⊕D2⊕D3⊕D4=0⊕0⊕1⊕1=1S_4 = P_4 \oplus D_2 \oplus D_3 \oplus D_4 = 0 \


oplus 0 \oplus 1 \oplus 1 = 1S4=P4⊕D2⊕D3⊕D4=0⊕0⊕1⊕1=1.

3. Syndrome: S=001S = 001S=001 (position 7 is erroneous).

4. Correct the error by flipping the 7th bit.

5. Corrected Codeword: 0,1,1,0,0,1,10, 1, 1, 0, 0, 1, 10,1,1,0,0,1,1.

Advantages of Hamming Codes

1. Detects and corrects single-bit errors.

2. Detects double-bit errors (cannot correct them).

3. Simple and efficient for small-scale error correction.

Applications of Linear Block Codes (including Hamming Codes)

1. Memory Systems: Single-bit error correction in RAM (e.g., ECC memory).

2. Data Communication: Ensuring reliable transmission in wireless networks.

3. Storage Systems: Used in RAID configurations for data redundancy.

Hamming codes are one of the simplest forms of linear block codes, making them a cornerstone for
understanding error control in digital systems.

You might also like