CN UNIT-3 Material
CN UNIT-3 Material
CN UNIT-3 Material
Flow Control, Error Detection and Correction – Error-Correcting Codes – Error Detecting Codes,
Elementary Data Link Protocols- A Utopian Simplex Protocol-A Simplex Stop and Wait Protocol for
an Error free channel-A Simplex Stop and Wait Protocol for a Noisy Channel, Sliding Window
Protocols-A One Bit Sliding Window Protocol-A Protocol Using Go-Back-NA Protocol Using
Selective Repeat
(i) Error Recovery.
(iii) User addressing.
(iii) Detection of errors.
The data link layer uses the services of the physical layer to send and receive bits over
communication channels.
It has a number of functions, including:
3. Regulating the flow of data so that slow receivers are not swamped by fast senders.
To accomplish these goals, the data link layer takes the packets it gets from the network
layer and encapsulates them into frames for transmission.
Each frame contains a frame header, a payload field for holding the packet, and a frame
trailer.
The function of the data link layer is to provide service to the network layer.
The principal service is transferring data from the network layer on the source machine to
the network layer on the destination machine.
The network layer hands some bits to the data link layer for transmission to the destination,
the job of the data link layer is to transmit the bits to the destination machine, so they can
be handed over to the network layer on the destination machine.
The job of the data link layer is to transmit the bits to the destination machine so they can
be handed over to the network layer there
Actual communication
In this communication, no physical medium is present for Data Link Layer to transmit data.
It can be only be visualized and imagined that two Data Link Layers are communicating with
each other with the help of or using data link protocol.
Virtual communication
In this communication, physical medium is present through which Data Link Layer simply
transmits data frames.
The actual path is Network Layer -> Data link layer -> Physical Layer on sending machine,
then to physical media and after that to Physical Layer -> Data link layer -> Network
Layer on receiving machine.
The data link layer can be designed to offer various services. The actual services that are
offered vary from protocol to protocol.
Three reasonable possibilities that we will consider in turn are:
Here, the data link layer of the sending machine sends independent frames to the data link
layer of the receiving machine.
The receiving machine does not acknowledge receiving the frame. No logical connection is
set up between the host machines. Error and data loss is not handled in this service.
This is applicable in Ethernet services and voice communications.
Here, no logical connection is set up between the host machines, but each frame sent by the
source machine is acknowledged by the destination machine on receiving.
If the source does not receive the acknowledgment within a stipulated time, then it resends
the frame.
This is used in Wifi (IEEE 802.11) services.
This is the best service that the data link layer can offer to the network layer.
A logical connection is set up between the two machines and the data is transmitted along
this logical path.
The frames are numbered, that keeps track of loss of frames and also ensures that frames
are received in correct order.
It is appropriate for satellite communications and long-distance telephone circuits.
It is appropriate for satellite communications and long-distance telephone circuits.
The service has three distinct phases –
1. Set up of connection – A logical path is set up between the source and the destination
machines. Buffers and counters are initialised to keep track of frames.
2. Sending frames – The frames are transmitted.
3. Release connection – The connection is released, buffers and other resources are
released.
Framing
The data link layer needs to pack bits into frames, so that each frame is distinguishable from
another.
Frames are generally data unit of data link layer that is transmitted or transferred among
various network points.
It includes complete and full addressing, protocols that are essential, and information under
control.
Physical layers only just accept and transfer stream of bits without any regard to meaning or
structure.
Therefore it is up to data link layer to simply develop and recognize frame boundaries. Data-
link layer takes the packets from the Network Layer and encapsulates them into frames.
If the frame size becomes too large, then the packet may be divided into small sized frames.
Smaller sized frames makes flow control and error control more efficient.
Then, it sends each frame bit-by-bit on the hardware. At receiver’s end, data link layer picks
up signals from hardware and assembles them into frames.
Parts of a Frame
1. Bit-oriented approach
HDLC-Frame format
8 16 16 8
In a data link frame, the delimiting flag sequence generally contains six or more consecutive
1s. In order to differentiate the message from the flag in case of the same sequence, a single
bit is stuffed in the message.
Whenever a 0 bit is followed by five consecutive 1bits in the message, an extra 0 bit is
stuffed at the end of the five 1s.
When the receiver receives the message, it removes the stuffed 0s after each sequence of
five 1s. The un-stuffed message is then sent to the upper layers.
8 8 8 8 8 16
1. SYN Character-It establishes synchronization of the incoming message with the receiver and
precedes all message packets. It can also be inserted into the middle of longer messages to
maintain synchronization
2. SOH –It indicates the Start Of Header
3. STX character –It signals the Start of TeXt
4. ETX character – It signals the End of TeXt
5. Payload-This is the actual message received from the Network layer.
Frame format
8 8 8 16 16
Flag -1 Byte that marks the beginning and the end of the frame. The bit pattern of the flag is
01111110
Address-1 byte which is set to 11111111 in case of broadcast
Control-1 byte set to a constant value of 11000000
Protocol-1 or 2 bytes that define the type of data contained in the payload field.
Payload –This carries the data from the network layer. The maximum length of the payload
field is 1500 bytes. However this may be negotiated between the endpoint of
communications
The danger is that if transmission error could corrupt the count field then the end of the frame
would not be correctly detected by the receiver.
Character stuffing
Byte stuffing or character stuffing is the process of adding one extra byte whenever there is
a flag sequence appear in the payload
Protocols in the data link layer are designed so that this layer can perform its basic functions:
1. Framing- Framing is the process of dividing bit - streams from physical layer into data
frames whose size ranges from a few hundred to a few thousand bytes
2. Error control- Error control mechanisms deals with transmission errors and
retransmission of corrupted and lost frames
3. Flow control-Flow control regulates speed of delivery and so that a fast sender does not
drown a slow receiver.
Error control
Error control is basically process in data link layer of detecting or identifying and re-
transmitting data frames that might be lost or corrupted during transmission.
In both of these cases, receiver or destination does not receive correct data-frame and
sender or source does not even know anything about any such loss regarding data frames.
Therefore, in such type of cases, both sender and receiver are provided with some essential
protocols that are required to detect or identify such type of errors like loss of data frames.
The Data-link layer follows technique known as re-transmission of frames to detect or
identify transit errors and also to take necessary actions that are required to reduce or
remove such errors. Each and every time an effort is detected during transmission, particular
data frames retransmitted and this process is known as ARQ (Automatic Repeat Request).
Error Detection :
Types of errors
There are 2 types of errors are there.
1. Bit error
2. Burst error
2. Burst error- In burst error, 2 or more bits in the data unit have changed
• Error detection means to decide whether the received data is correct or not without having
a copy of the original message.
• To detect or correct errors, we need to send some extra bits with the data.
2. Checksum
2.Checksum
Checksums are similar to parity bits except, the number of bits in the sums is larger than
parity and the result is always constrained to be zero. That means if the checksum is zero,
error is detected. A checksum of a message is an arithmetic sum of code words of certain
length. The sum is stated by means of 1’s compliment and stored or transferred as a code
extension of actual code word. At receiver a new checksum is calculated by receiving the bit
sequence from transmitter.
The checksum method includes parity bits, check digits and longitudinal redundancy check
(LRC). For example, if we have to transfer and detect errors for a long data sequence (also
called as Data string) then we divide that into shorter words and we can store the data with
a word of same width. For each another incoming bit we will add them to the already stored
data. At every instance, the newly added word is called “Checksum”.
At receiver side, the received bits checksum is same as that of transmitter’s, there is no error
found.
1.Break the original message into ‘k’ number of blocks with ‘n’ bits in each block.
Solution
Step 1: Break the original message into ‘k’ number of blocks with ‘n’ bits in each block.
In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are appended to
the end of data unit so that the resulting data unit becomes exactly divisible by a second,
predetermined binary number.
At the destination, the incoming data unit is divided by the same number. If at this step
there is no remainder, the data unit is assumed to be correct and is therefore accepted.
A remainder indicates that the data unit has been damaged in transit and therefore must be
rejected.
CRC generation at sender side
1. At the receiver side, we divide the received code word with the same divisor to get the
actual code word.
2. For an error free reception of data, the reminder is 0. If the reminder is a non – zero,
that means there is an error in the received code / data sequence.
Example
Find the CRC for the data blocks 100100 with the divisor 1101?
At sender side
At receiver side
Error correction, as name suggests, simply means correction or solving or fixing of errors.
It simply means reconstruction and rehabilitation of original data that is error-free. But error
correction method is very costly and is very hard.
The techniques that we have discussed o far can detect errors, but do not correct them.
Error correction can be handled in 2 ways
1. One I when error is discovered, the receiver can have the sender retransmit the entire
data unit
2. The receiver can use an error correcting code which automatically corrects certain errors.
Hamming Code
This error detecting and correcting code technique is developed by R.W.Hamming . This
code not only identifies the error bit, in the whole data sequence and it also corrects it.
This code uses a number of parity bits located at certain positions in the code word. The
number of parity bits depends upon the number of information bits.
The hamming code uses the relation between redundancy bits and the data bits and this
code can be applied to any number of data bits.
Redundancy means “The difference between number of bits of the actual data sequence and
the transmitted bits”. These redundancy bits are used in communication system to detect
and correct the errors, if any.
How the Hamming code actually corrects the errors?
In Hamming code, the redundancy bits are placed at certain calculated positions in order to
eliminate errors. The distance between the two redundancy bits is called “Hamming
distance”.
To understand the working and the data error correction and detection mechanism of the
hamming code, let’s see to the following stages.
Parity bits
• A parity bit is a bit appended to a data of binary bits to ensure that the total number of 1’s in
the data is even or odd. Parity bits are used for error detection. There are two types of parity
bits:
• In the case of odd parity, for a given set of bits, the number of 1’s are
counted. If that count is even, the parity bit value is set to 1, making the
total count of occurrences of 1’s an odd number. If the total number of 1’s in
a given set of bits is already odd, the parity bit’s value is 0.
• All bit positions that are power of 2 marked as parity bits(1,2,4,8…) and the remaining bits
are marked as data bits.
D7 D6 D5 P4 D3 P2 P1
D-data bit
P-parity bit
P1 D3 D5 D7
P1 1 0 1
P1=1
P2 D3 D6 D7
P2 1 1 1
P2=0
P4 D5 D6 D7
P4 0 1 1
P4=1
Detecting errors
Correcting of errors
1 0 1
The decimal value for E=5(101) which shows that 5 th bit is in error.
Flow control
Flow control is a technique that allows two stations working at different speeds to
communicate with each other.
It is a set of measures taken to regulate the amount of data that a sender sends so that a
fast sender does not overwhelm a slow receiver.
In data link layer, flow control restricts the number of frames the sender can send before it
waits for an acknowledgment from the receiver.
Simplex protocol
The Simplex protocol is data link layer protocol for transmission of frames over computer
network.
It is hypothetical protocol designed for unidirectional data transmission over an ideal
channel, i.e. a channel through which transmission can never go wrong.
It is assumed that both the sender and the receiver are always ready for data processing and
both of them have infinite buffer.
The sender simply sends all its data available onto the channel as soon as they are available
its buffer.
The receiver is assumed to process all incoming data instantly. It is does not handle flow
control or error control. Since this protocol is totally unrealistic, it is often called Utopian
Simplex protocol.
Design
Sender Site:
1. The data link layer in the sender site waits for the network layer to send a data packet.
2. On receiving the packet, it immediately processes it and sends it to the physical layer for
transmission.
Receiver Site:
1. The data link layer in the receiver site waits for a frame to be available.
2. When it is available, it immediately processes it and sends it to the network layer.
Stop-and-Wait Protocol
It is a data link layer protocol for transmission of frames over noiseless channels.
It provides unidirectional data transmission with flow control facilities but without error
control facilities.
After transmitting one frame ,the sender waits for an acknowledgement before transmitting
the next frame.
Design
Sender side
Rule 2-Send the next packet only after receiving acknowledgement for the previous.
Receiver side
After timeout on sender side, a delayed AK might be wrongly considered as ACK of some
other data packet.
3. Stop-and-Wait ARQ
Sliding Window
This protocol improves the efficiency of stop and waits protocol by allowing multiple frames
to be transmitted before receiving an acknowledgment.
The working principle of this protocol can be described as follows –
Both the sender and the receiver has finite sized buffers called windows. The sender and the
receiver agrees upon the number of frames to be sent based upon the buffer size.
The sender sends multiple frames in a sequence, without waiting for acknowledgment.
When its sending window is filled, it waits for acknowledgment.
On receiving acknowledgment, it advances the window and transmits the next frames,
according to the number of acknowledgments received.
Go-back-N-ARQ
Go-back-N-ARQ uses the concept of protocol pipelining i.e., the sender can send multiple
frames before receiving the ACK for the first frame.
There are finite number of frame and the frames are numbered in a sequence manner.
The number of frames that can be sent depends on the window size of the sender.
If the ACK of a frame I not received within an agreed upon time period,all frames in the
current window are transmitted.
Working Principle
Go – Back – N ARQ provides for sending multiple frames before receiving the
acknowledgment for the first frame.
The frames are sequentially numbered and a finite number of frames. The maximum
number of frames that can be sent depends upon the size of the sending window.
If the acknowledgment of a frame is not received within an agreed upon time period, all
frames starting from that frame are retransmitted.
The size of the sending window determines the sequence number of the outbound frames. If
the sequence number of the frames is an n-bit field, then the range of sequence numbers
that can be assigned is 0 to 2n−1.
Consequently, the size of the sending window is 2n−1. Thus in order to accommodate a
sending window size of 2n−1, a n-bit sequence number is chosen.
The sequence numbers are numbered as modulo-n. For example, if the sending window size
is 4, then the sequence numbers will be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and so on.
The number of bits in the sequence number is 2 to generate the binary sequence 00, 01, 10,
11.
Working Principle
Selective Repeat protocol provides for sending multiple frames depending upon the
availability of frames in the sending window, even if it does not receive acknowledgement
for any frame in the interim.
The maximum number of frames that can be sent depends upon the size of the sending
window.
The receiver records the sequence number of the earliest incorrect or un-received frame. It
then fills the receiving window with the subsequent frames that it has received.
It sends the sequence number of the missing frame along with every acknowledgement
frame.
The sender continues to send frames that are in its sending window. Once, it has sent all the
frames in the window, it retransmits the frame whose sequence number is given by the
acknowledgements. It then continues sending the other frames.