You are on page 1of 14

UNIT-III

DATA LINK LAYER

Link Layer: Types of errors –Error detection- VRC, LRC, CRC techniques - Data Forward
and backward error correction - Hamming code. Flow control: stop and wait- sliding window
protocol, Error control: Stop and wait ARQ- Go-Back-N ARQ- Selective Repeat ARQ
Protocols- Asynchronous and Synchronous Protocol - HDLC frames.

DATA LINK LAYER


 Data Link Layer is second layer of OSI Layered Model.
 The communication channel that connects the adjacent nodes is known as links, and
in order to move the datagram from source to the destination, the datagram must
be moved across an individual link.
 The main responsibility of the Data Link Layer is to transfer the datagram across an
individual link.
 The Data link layer protocol defines the format of the packet exchanged across the
nodes as well as the actions such as Error detection, retransmission, flow control,
and random access.
 The Data Link Layer protocols are Ethernet, token ring, FDDI and PPP.
 An important characteristic of a Data Link Layer is that datagram can be handled by
different link layer protocols on different links in a path. For example, the datagram
is handled by Ethernet on the first link, PPP on the second link.
Data link layer has two sub-layers:
 Logical Link Control: It deals with protocols, flow-control, and error control
 Media Access Control: It deals with actual control of media
Functionality of Data-link Layer

 Framing & Link access: Data Link Layer protocols encapsulate each network frame
within a Link layer frame before the transmission across the link. A frame consists of
a data field in which network layer datagram is inserted and a number of data fields.
It specifies the structure of the frame as well as a channel access protocol by which
frame is to be transmitted over the link.
 Reliable delivery: Data Link Layer provides a reliable delivery service, i.e., transmits
the network layer datagram without any error. A reliable delivery service is
accomplished with transmissions and acknowledgements. A data link layer mainly
provides the reliable delivery service over the links as they have higher error rates
and they can be corrected locally, link at which an error occurs rather than forcing to
retransmit the data.
 Flow control: A receiving node can receive the frames at a faster rate than it can
process the frame. Without flow control, the receiver's buffer can overflow, and
frames can get lost. To overcome this problem, the data link layer uses the flow
control to prevent the sending node on one side of the link from overwhelming the
receiving node on another side of the link.
 Error detection: Errors can be introduced by signal attenuation and noise. Data Link
Layer protocol provides a mechanism to detect one or more errors. This is achieved
by adding error detection bits in the frame and then receiving node can perform an
error check.
 Error correction: Error correction is similar to the Error detection, except that
receiving node not only detect the errors but also determine where the errors have
occurred in the frame.
 Half-Duplex & Full-Duplex: In a Full-Duplex mode, both the nodes can transmit the
data at the same time. In a Half-Duplex mode, only one node can transmit the data
at the same time.
 Synchronization
 When data frames are sent on the link, both machines must be synchronized in
order to transfer to take place.
Three Types of addresses
Some link-layer protocols define three types of addresses: unicast, multicast, and broadcast.
 Unicast Address
Each host or each interface of a router is assigned a unicast address. Unicasting
means one-to-one communication. A frame with a unicast address destination is
destined only for one entity in the link.
 Multicast Address
Some link-layer protocols define multicast addresses. Multicasting means one-to-
many communication. However, the jurisdiction is local (inside the link).
 Broadcast Address
Some link-layer protocols define a broadcast address. Broadcasting means one-to-all
communication. A frame with a destination broadcast address is sent to all entities in
the link.

TYPES OF ERRORS
Error
 A condition when the receiver’s information does not match with the sender’s
information.
 During transmission, digital signals suffer from noise that can introduce errors in the
binary bits travelling from sender to receiver.
 That means a 0 bit may change to 1 or a 1 bit may change to 0.

 Errors can be classified into two categories:


o Single-Bit Error
o Burst Error
Single-Bit Error:
 The only one bit of a given data unit is changed from 1 to 0 or from 0 to 1.

 In the above figure, the message which is sent is corrupted as single-bit, i.e., 0 bit is
changed to 1.
 Single-Bit Error does not appear more likely in Serial Data Transmission.
 For example, Sender sends the data at 10 Mbps, this means that the bit lasts only for
1 ?s and for a single-bit error to occurred, a noise must be more than 1 ?s.
 Single-Bit Error mainly occurs in Parallel Data Transmission.
 For example, if eight wires are used to send the eight bits of a byte, if one of the wire
is noisy, then single-bit is corrupted per byte.
Burst Error:
 The two or more bits are changed from 0 to 1 or from 1 to 0 is known as Burst Error.
 The Burst Error is determined from the first corrupted bit to the last corrupted bit.

 The duration of noise in Burst Error is more than the duration of noise in Single-Bit.
 Burst Errors are most likely to occurr in Serial Data Transmission.
 The number of affected bits depends on the duration of the noise and data rate.

ERROR DETECTION METHODS


 Following are the error detection methods or techniques of error detection in
networking.
1. VRC Method
2. LRC method
3. CRC method
1. Cyclic Redundancy Check (CRC)
CRC is a redundancy error technique used to determine the error.
Following are the steps used in CRC for error detection:
 CRC is a different approach to detect if the received frame contains valid data.
 This technique involves binary division of the data bits being sent.
 The divisor is generated using polynomials.
 The sender performs a division operation on the bits being sent and calculates the
remainder.
 Before sending the actual bits, the sender adds the remainder at the end of the
actual bits.
 Actual data bits plus the remainder is called a codeword. The sender transmits data
bits as code words.
 The receiver receives the data followed by the CRC remainder.
 The receiver will treat this whole unit as a single unit, and it is divided by the same
divisor that was used to find the CRC remainder.
 If the resultant of this division is zero which means that it has no error, and the data
is accepted.
 If the resultant of this division is not zero which means that the data consists of an
error. Therefore, the data is discarded.

EXAMPLE:
Suppose the original data is 11100 and divisor is 1001.
CRC Generator
 A CRC generator uses a modulo-2 division. Firstly, three zeroes are appended at the
end of the data as the length of the divisor is 4 and we know that the length of the
string 0s to be appended is always one less than the length of the divisor.
 Now, the string becomes 11100000, and the resultant string is divided by the divisor
1001.
 The remainder generated from the binary division is known as CRC remainder. The
generated value of the CRC remainder is 111.
 CRC remainder replaces the appended string of 0s at the end of the data unit, and
the final string would be 11100111 which is sent across the network.

CRC Checker
 The functionality of the CRC checker is similar to the CRC generator.
 When the string 11100111 is received at the receiving end, then CRC checker
performs the modulo-2 division.
 A string is divided by the same divisor, i.e., 1001.
 In this case, CRC checker generates the remainder of zero. Therefore, the data is
accepted.

2. Parity check or vertical redundancy check (VRC) method

 One extra bit is sent along with the original bits to make number of 1s either even in
case of even parity, or odd in case of odd parity.
 The sender while creating a frame counts the number of 1s in it.
 For example, if even parity is used and number of 1s is even then one bit with value
0 is added.
 This way number of 1s remains even.If the number of 1s is odd, to make it even a bit
with value 1 is added.

 The receiver simply counts the number of 1s in a frame. If the count of 1s is even
and even parity is used, the frame is considered to be not-corrupted and is
accepted.
 If the count of 1s is odd and odd parity is used, the frame is still not corrupted.
 If a single bit flips in transit, the receiver can detect it by counting the number of 1s.
 But when more than one bits are erro neous, then it is very hard for the receiver to
detect the error.
Drawbacks Of Single Parity Checking
 It can only detect single-bit errors which are very rare.
 If two bits are interchanged, then it cannot detect the errors.
Two-Dimensional Parity Check
 Performance can be improved by using Two-Dimensional Parity Check which
organizes the data in the form of a table.
 Parity check bits are computed for each row, which is equivalent to the single-parity
check.
 In Two-Dimensional Parity check, a block of bits is divided into rows, and the
redundant row of bits is added to the whole block.
 At the receiving end, the parity bits are compared with the parity bits computed
from the received data.

Drawbacks Of 2D Parity Check


 If two bits in one data unit are corrupted and two bits exactly the same position in
another data unit are also corrupted, then 2D Parity checker will not be able to
detect the error.
 This technique cannot be used to detect the 4-bit errors or more in some cases.

3. Longitudinal Redundancy Check (LRC) method

 In this error detection method, a block of bits are organized in a table (of rows and
columns).
 For example, instead of sending block of 32 bits, first it is organized into four rows
and eight columns.
 Then parity bits for each column is calculated and new row of eight parity bits is
formed.
 These eight parity bits are appended to original data before transmission.
FLOW CONTROL
 Whenever an entity produces items and another entity consumes them, there
should be a balance between production and consumption rates.
 If the items are produced faster than they can be consumed, the consumer can be
overwhelmed and may need to discard some items.
 If the items are produced more slowly than they can be consumed, the consumer
must wait, and the system becomes less efficient.

Flow Control Definition:


 In data communications, flow control is the process of managing the rate of data
transmission between two nodes to prevent a fast sender from overwhelming a
slow receiver.
 When a data frame (Layer-2 data) is sent from one host to another over a single
medium, it is required that the sender and receiver should work at the same speed.

Two types of mechanisms


i) STOP AND WAIT PROTOCOL
 Stop-and-wait flow control is the simplest form of flow control.
 This flow control mechanism forces the sender after transmitting a data frame to
stop and wait until the acknowledgement of the data-frame sent is received.
Working
 The working of a stop and wait protocol may be explained as-
 Sender sends a data packet to the receiver.
 Sender stops and waits for the acknowledgement for the sent packet from the
receiver.
 Receiver receives and processes the data packet.
 Receiver sends an acknowledgement to the sender.
 After receiving the acknowledgement, sender sends the next data packet to the
receiver.
 Go to step 1 when ACK is not received, or time out is hit.

Sender States The sender is initially in the ready state, but it can move between the ready
and blocking state.
 Ready State.
When the sender is in this state, it is only waiting for a packet from the network layer.
If a packet comes from the network layer, the sender creates a frame, saves a copy of the
frame, starts the only timer and sends the frame.
The sender then moves to the blocking state.
 Blocking State.
When the sender is in this state, three events can occur:
a. If a time-out occurs, the sender resends the saved copy of the frame and restarts the
timer.
b. If a corrupted ACK arrives, it is discarded.
c. If an error-free ACK arrives, the sender stops the timer and discards the saved copy of
the frame. It then moves to the ready state.

Receiver State:The receiver is always in the ready state.

Two events may occur:


a. If an error-free frame arrives, the message in the frame is delivered to the network layer
and an ACK is sent.
b. If a corrupted frame arrives, the frame is discarded.
Pros
The only advantage of this method of flow control is its simplicity.
Cons
The sender needs to wait for the ACK after every frame it transmits. This is a source of
inefficiency, and is particularly bad when the propagation delay is much longer than the
transmission delay.

ii) SLIDING WINDOW PROTOCOL:


 In this flow control mechanism, both sender and receiver agree on the number of
data-frames after which the acknowledgement should be sent.
 In this protocol, multiple frames can be sent by a sender at a time before receiving
an acknowledgment from the receiver.
 Sliding window method is also known as windowing.
Working:
 The sliding window algorithm works as follows.
 First, the sender assigns a sequence number, denoted SeqNum, to each frame.
 The sender maintains three variables:
 The send window size, denoted SWS, gives the upper bound on the number of
outstanding (unacknowledged) frames that the sender can transmit;
 LAR denotes the sequence number of the last acknowledgment received;
 LFS denotes the sequence number of the last frame sent.
 The sender also maintains the following invariant:

 When an acknowledgment arrives, the sender moves LAR to the right, thereby
allowing the sender to transmit another frame.
 Also, the sender associates a timer with each frame it transmits, and it retransmits
the frame should the timer expire before an ACK is received.
 Notice that the sender has to be willing to buffer up to SWS frames since it must be
prepared to retransmit them until they are acknowledged.
 The receiver maintains the following three variables:
 The receive window size, denoted RWS, gives the upper bound on the number of
out-of-order frames that the receiver is willing to accept;
 LAF denotes the sequence number of the largest acceptable frame; and LFR denotes
the sequence number of the last frame received.
 The receiver also maintains the following invariant:

ERROR CONTROL
 Error control in data link layer is the process of detecting and correcting data
frames that have been corrupted or lost during transmission.
Requirements for error control mechanism:
 Error detection  - The sender and receiver, either both or any, must ascertain that
there is some error in the transit.
 Positive ACK  - When the receiver receives a correct frame, it should acknowledge it.
 Negative ACK  - When the receiver receives a damaged frame or a duplicate frame,
it sends a NACK back to the sender and the sender must retransmit the correct
frame.
 Retransmission:  The sender maintains a clock and sets a timeout period. If an
acknowledgement of a data-frame previously transmitted does not arrive before the
timeout the sender retransmits the frame, thinking that the frame or it’s
acknowledgement is lost in transit.
Error Control Techniques:
Types of Sliding Window Protocols:
i) Stop-and-wait ARQ

 The following transition may occur in Stop-and-Wait ARQ:


 The sender maintains a timeout counter.
 When a frame is sent, the sender starts the timeout counter.
 If acknowledgement of frame comes in time, the sender transmits the next
frame in queue.
 If acknowledgement does not come in time, the sender assumes that either
the frame or its acknowledgement is lost in transit. Sender retransmits the
frame and starts the timeout counter.
 If a negative acknowledgement is received, the sender retransmits the frame.
ii) Go-Back-N ARQ
 Stop and wait ARQ mechanism does not utilize the resources at their best.When the
acknowledgement is received, the sender sits idle and does nothing.
 In Go-Back-N ARQ method, both sender and receiver maintain a window.

 The sending-window size enables the sender to send multiple frames without
receiving the acknowledgement of the previous ones.
 The receiving-window enables the receiver to receive multiple frames and
acknowledge them.
 The receiver keeps track of incoming frame’s sequence number.
 When the sender sends all the frames in window, it checks up to what sequence
number it has received positive acknowledgement.
 If all frames are positively acknowledged, the sender sends next set of frames.
 If sender finds that it has received NACK or has not receive any ACK for a particular
frame, it retransmits all the frames after which it does not receive any positive ACK.

iii) Selective Repeat ARQ


 Both the sender and the receiver have buffers called sending window and receiving
window respectively.
 The sender sends multiple frames based upon the sending-window size, without
receiving the acknowledgment of the previous ones.
 The receiver also receives multiple frames within the receiving window size.
 The receiver keeps track of incoming frame’s sequence numbers, buffers the frames
in memory.
 It sends ACK for all successfully received frames and sends NACK for only frames
which are missing or damaged.
 The sender in this case, sends only packet for which NACK is received.
ASYNCHRONOUS TRANSMISSION
 Asynchronous transmission is a type of serial transmission that follows a non-
synchronized form of communication.
 Thus start and stop bits are required in order to intimate the receiver about the
beginning and end of the data stream.
 Here the data is transferred from an end to another in the form of bytes or
characters.
 Thus when the transmitter wants to send data then it has to notify the receiver that
it is going to send the data bits.
 So for this reason before sending the actual data the transmitter sends a start bit
that notifies the receiver about the transmission.
 To alert the receiver to the arrival of a new group, therefore, an extra bit is added to
the beginning of each byte.
 This bit, usually a 0, is called the start bit.
 To let the receiver know that the byte is finished, 1 or more additional bits are
appended to the end of the byte.
 These bits, usually 1s, are called stop bits.

SYNCHRONOUS TRANSMISSION
 In synchronous transmission, the bit stream is combined into longer “frames,” which
the name itself is indicating that synchronous transmission needs synchronization
between transmitter and receiver in order to allow communication between the
two.
 Basically, despite having internal clock pulses, the transmitter and receiver share a
common clock pulse so as to have synchronization in communication.
 This means data will be transmitted between the transmitter and receiver only after
a constant time interval.
 It allows the transmission of data in the form of frames or blocks. Thus a huge data
amount can be transmitted between transmitter and receiver once the clock pulse is
sent.

HDLC FRAMES
 High-level Data Link Control (HDLC) is a bit-oriented protocol for communication
over point-to-point and multipoint links.
 It implements the Stop-and-Wait protocol.
 Since it is a data link protocol, data is organized into frames.
Transfer Modes
 HDLC supports two types of transfer modes, normal response mode and
asynchronous balanced mode.
 Normal Response Mode (NRM) − Here, two types of stations are there, a primary
station that send commands and secondary station that can respond to received
commands. It is used for both point - to - point and multipoint communications.
 Asynchronous Balanced Mode (ABM) − Here, the configuration is balanced, i.e.
each station can both send commands and respond to commands. It is used for only
point - to - point communications.
HDLC Frame
 HDLC is a bit - oriented protocol where each frame contains up to six fields. The
structure varies according to the type of frame. The fields of a HDLC frame are −
 Flag − It is an 8-bit sequence that marks the beginning and the end of the frame. The
bit pattern of the flag is 01111110.
 Address − It contains the address of the receiver. If the frame is sent by the primary
station, it contains the address(es) of the secondary station(s). If it is sent by the
secondary station, it contains the address of the primary station. The address field
may be from 1 byte to several bytes.
 Control − It is 1 or 2 bytes containing flow and error control information.
 Payload − This carries the data from the network layer. Its length may vary from one
network to another.
 FCS − It is a 2 byte or 4 bytes frame check sequence for error detection. The standard
code used is CRC (cyclic redundancy code)
Types of HDLC Frames
 There are three types of HDLC frames. The type of frame is determined by the
control field of the frame −
 I-frame − I-frames or Information frames carry user data from the network layer.
They also include flow and error control information that is piggybacked on user
data. The first bit of control field of I-frame is 0.
 S-frame − S-frames or Supervisory frames do not contain information field. They are
used for flow and error control when piggybacking is not required. The first two bits
of control field of S-frame is 10.
 U-frame − U-frames or Un-numbered frames are used for myriad miscellaneous
functions, like link management. It may contain an information field, if required. The
first two bits of control field of U-frame is 11.

ERROR CORRECTION
 In the digital world, error correction can be done in two ways:
 Backward Error Correction  When the receiver detects an error in the data received,
it requests back the sender to retransmit the data unit.
 Forward Error Correction  When the receiver detects some error in the data
received, it executes error-correcting code, which helps it to auto-recover and to
correct some kinds of errors.
 The first one, Backward Error Correction, is simple and can only be efficiently used
where retransmitting is not expensive.
 For example, fiber optics. But in case of wireless transmission retransmitting may
cost too much.
 In the latter case, Forward Error Correction is used. To correct the error in data
frame, the receiver must know exactly which bit in the frame is corrupted.
 To locate the bit in error, redundant bits are used as parity bits for error detection.
 For example, we take ASCII words (7 bits data), then there could be 8 kind of
information we need: first seven bits to tell us which bit is error and one more bit to
tell that there is no error.
 For m data bits, r redundant bits are used. r bits can provide 2r combinations of
information.
 In m+r bit codeword, there is possibility that the r bits themselves may get
corrupted. So the number of r bits used must inform about m+r bit locations plus
no-error information, i.e. m+r+1.

HAMMING CODE
Hamming code is a set of error-correction codes that can be used to detect and correct the
errors that can occur when the data is moved or stored from the sender to the receiver. It is
technique developed by R.W. Hamming for error correction.

Example:
Data = 10011010
No of parity bits to be added to data: >= m + r + 1 ……. (i)
where,
   r = number of parity bits,
   m = number of message bits

Let’s assume we first take r = 4.


Now, using equation (i)
>= 8 + 4 + 1 (Therefore, the inequality holds)

The parity bits are added at power of 2’s position. For example, position will be 1st ( ), 2nd
( ), 4th ( ), 8th ( ) …and so on.

Now, total bits that will be sent to the receiver will be the message bits + parity bits. So, final
bits will be 1 001 1010.
To find the parity bits, we start from position. we take ‘i’ bits and leave the next ‘i’ bits.
Then, again consider the next ‘i’ bits and continue the process till the last bit.
Finding parity bits at the Sender’s Side:

Finding Parity Bits


Thus, the data to be sent to the receiver after padding the parity bits is:

Final Data
Finding the parity bits on Receiver’s Side:
Now, assume the received code word is
Data Received by Receiver
The receiver will also find the parities using the same method.
Now, total bits that will be sent to the receiver will be the message bits + parity bits.

Finding parity bits


Now, to find the parity bits, we start from position. We take ‘i’ bits and leave the next ‘i’
bits. Again, consider the next ‘i’ bits and continue the process till the last bit.

Finding parity bits steps


The receiver received the parity set to be 0, 1, 1, 0 . But, the calculated parity set here is 0,
0, 1, 1. Thus, there is an error at 2 + 8 = 10th position. So, the bit at 10th position is
complemented. Hence, the error is corrected.

Error correction

You might also like