CN Notes - Unit - II
CN Notes - Unit - II
Data link layer: Design issues, framing, Error detection and correction. Elementary data link protocols: simplex
protocol, A simplex stop and wait protocol for an error-free channel, A simplex stop and wait protocol for noisy
channels.
Sliding Window protocols: A one-bit sliding window protocol, A protocol using Go-Back-N, A protocol using
Selective Repeat, Example data link protocols.
Data-link layer is the second layer after the physical layer. The data link layer is responsible
for maintaining the data link between two hosts or nodes.
Before going through the design issues in the data link layer. Some of its sub-layers and their
functions are as follows below.
The data link layer is divided into two sub-layers :
1. Logical Link Control Sublayer (LLC) –
Provides the logic for the data link, Thus it controls the synchronization, flow control, and error
checking functions of the data link layer. Functions are –
○ (i) Error Recovery.
○ (ii) It performs the flow control operations.
○ (iii) User addressing.
Framing
Data-link layer is the second layer after the physical layer. The data link layer is responsible
for maintaining the data link between two hosts or nodes.
Before going through the design issues in the data link layer. Some of its sub-layers and their
functions are as follows below.
The data link layer is divided into two sub-layers :
1. Logical Link Control Sublayer (LLC) –
Provides the logic for the data link, Thus it controls the synchronization, flow control, and error
checking functions of the data link layer. Functions are –
○ (i) Error Recovery.
○ (ii) It performs the flow control operations.
○ (iii) User addressing.
At the data link layer, it extracts the message from the sender and provides it to the receiver
by providing the sender’s and receiver’s addresses. The advantage of using frames is that
data is broken up into recoverable chunks that can easily be checked for corruption.
Problems in Framing –
● Detecting start of the frame: When a frame is transmitted, every station must be able
to detect it. Station detects frames by looking out for a special sequence of bits that marks the
beginning of the frame i.e. SFD (Starting Frame Delimiter).
● How does the station detect a frame: Every station listens to a link for SFD pattern
through a sequential circuit. If SFD is detected, a sequential circuit alerts the station. Station
checks the destination address to accept or reject the frame.
● Detecting end of frame: When to stop reading the frame.
2. Variable size – In this, there is a need to define the end of the frame as well as the
beginning of the next frame to distinguish. This can be done in two ways:
1) Length field – We can introduce a length field in the frame to indicate the length of the
frame. Used in Ethernet(802.3). The problem with this is that sometimes the length field
might get corrupted.
2) End Delimiter (ED) – We can introduce an ED(pattern) to indicate the end of the
frame. Used in Token Ring. The problem with this is that ED can occur in the data. This can
be solved by:
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 traveling from sender to receiver. That means a 0 bit may change to 1 or a 1 bit
may change to 0.
Error Detecting Codes (Implemented either at Data link layer or Transport Layer of OSI
Model)
Whenever a message is transmitted, it may get scrambled by noise or data may get
corrupted. To avoid this, we use error-detecting codes which are additional data added to a
given digital message to help us detect if any error has occurred during transmission of the
message.
Basic approach used for error detection is the use of redundancy bits, where additional bits
are added to facilitate detection of errors.
Some popular techniques for error detection are:
1. Simple Parity check
2. Two-dimensional Parity check
3. Checksum
4. Cyclic redundancy check
1. Simple Parity check
Blocks of data from the source are subjected to a check bit or parity bit generator form, where
a parity of :
● 1 is added to the block if it contains odd number of 1’s, and
● 0 is added if it contains even number of 1’s
This scheme makes the total number of 1’s even, that is why it is called even parity checking.
2.
Two-dimensional Parity check
Parity check bits are calculated for each row, which is equivalent to a simple parity check bit.
Parity check bits are also calculated for all columns, then both are sent along with the data. At
the receiving end these are compared with the parity bits calculated on the received data
3. Checksum
● In the checksum error detection scheme, the data is divided into k segments each of m
bits.
● In the sender’s end the segments are added using 1’s complement arithmetic to get the
sum. The sum is complemented to get the checksum.
● The checksum segment is sent along with the data segments.
● At the receiver’s end, all received segments are added using 1’s complement arithmetic
to get the sum. The sum is complemented.
● If the result is zero, the received data is accepted; otherwise discarded.
Protocols in the data link layer are designed so that this layer can perform its basic functions: framing,
error control and flow control. Framing is the process of dividing bits - streams from the physical layer
into data frames whose size ranges from a few hundred to a few thousand bytes. Error control
mechanisms deal with transmission errors and retransmission of corrupted and lost frames. Flow
control regulates speed of delivery and so that a fast sender does not drown a slow receiver.
Types of Data Link Protocols
Data link protocols can be broadly divided into two categories, depending on whether the
transmission channel is noiseless or noisy.
Simplex Protocol
The Simplex protocol is a hypothetical protocol designed for unidirectional data transmission over an
ideal channel, i.e. a channel through which transmission can never go wrong. It has distinct
procedures for sender and receiver. The sender simply sends all its data available onto the channel
as soon as they are available in its buffer. The receiver is assumed to process all incoming data
instantly. It is hypothetical since it does not handle flow control or error control.
Stop – and – Wait protocol is for noiseless channels too. It provides unidirectional data transmission
without any error control facilities. However, it provides for flow control so that a fast sender does not
drown a slow receiver. The receiver has a finite buffer size with finite processing speed. The sender
can send a frame only when it has received indication from the receiver that it is available for further
data processing.
Stop – and – wait Automatic Repeat Request (Stop – and – Wait ARQ) is a variation of the above
protocol with added error control mechanisms, appropriate for noisy channels. The sender keeps a
copy of the sent frame. It then waits for a finite time to receive a positive acknowledgement from the
receiver. If the timer expires or a negative acknowledgement is received, the frame is retransmitted. If
a positive acknowledgement is received then the next frame is sent.
Go – Back – N ARQ
Go – Back – N ARQ provides for sending multiple frames before receiving the acknowledgement for
the first frame. It uses the concept of sliding window, and so is also called sliding window protocol.
The frames are sequentially numbered and a finite number of frames are sent. If the
acknowledgement of a frame is not received within the time period, all frames starting from that frame
are retransmitted.
This protocol also provides for sending multiple frames before receiving the acknowledgement for the
first frame. However, here only the erroneous or lost frames are retransmitted, while the good frames
are received and buffered.
We will consider a protocol that is simply because it does not worry about the possibility of
anything going wrong. Data is transmitted in one direction only. Both transmitting and
receiving network layers are always ready. Processing time can be ignored. Infinite buffer
space is available. This thoroughly unrealistic protocol, which we will nickname “Utopia”, is
simply to show the basic structure on which we will build. Its implementation is shown below.
Utopian simplex Protocol: There is one direction of data transmission only from sender to
receiver. Here we assume the communication channel to be error-free and the receiver will
infinitely quickly process the input. The sender pumps out the data onto the line as fast as it
can.
#include"protocol.h"
void sender1(void)
{
frame s; /* buffer for an outbound frame */
packet buffer; /* buffer for an outbound packet */
while(true)
{
from_network_layer(&buffer); /* go get something to send */
[Link]=buffer; /* copy it into s for transmission */
to_physical_layer(&s); /* send it on its way */
}
}
void receiver1(void)
{
frame r;
event_type event; /* filled in by wait, but not used here */
while(true)
{
wait_for_event(n event); /* only possibility is frame_arrival */
from_physical_layer(&r); /* go get the inbound frame */
to_network_layer(&[Link]); /* pass the data to the network layer */
}
}
This protocol has two different procedures, a sender and a receiver. MAX_SEQ is not needed
because no sequence numbers or acknowledgements are used. The only event type possible
is frame_arrival (i.e. the arrival of an undamaged frame). The sender pumps out the data in
an infinite while loop as fast as it can. The loop body consists of three actions and they are –
● Fetch a packet from the network layer,
● Construct an outbound frame using the variable s,
● Send the frame on its way.
Other fields have to do with error and flow control and there are no errors or flow control
restrictions here so only the info field is used here. The receiver is equally simple. The
procedure wait_for_event returns when the frame arrives and the event is set to
frame_arrival. The newly arrived frame from the hardware buffer is removed by the call
from_physical_layer and put in the variable r, so that receiver can get it. The data link layer
settles back to wait for the next frame when the data portion is passed on to the network
layer, suspending itself until the frame arrives. It does not handle either flow control or error
correction therefore it is unrealistic.
Properties of Utopian Simplex Protocol:
● The design of Utopian Simplex Protocol is based on 2 procedures i.e. Sender and
Receiver.
● Both Sender and Receiver run in the data link layer but the sender runs in the data link
layer of the source machine while Receiver runs in the data link layer of the destination
machine.
● It is designed for Unidirectional data transmission.
● Sender and receiver are always ready for data processing.
● Both of them have infinite buffer space available.
● The communication links never lose any data frames.
● It is considered as unrealistic as it does not handle flow control or error correction.
Stop – and – Wait protocol is 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.
This protocol takes into account the fact that the receiver has a finite processing speed. If data frames
arrive at the receiver’s end at a rate which is greater than its rate of processing, frames are dropped
out. In order to avoid this, the receiver sends an acknowledgement for each frame upon its arrival.
The sender sends the next frame only when it has received a positive acknowledgement from the
receiver that it is available for further data processing.
Design
● Sender Site: The data link layer in the sender site waits for the network layer for a data packet.
It then checks whether it can send the frame. If it receives a positive notification from the physical
layer, it makes frames out of the data and sends it. It then waits for an acknowledgement before
sending the next frame.
● Receiver Site: The data link layer in the receiver site waits for a frame to arrive. When it
arrives, the receiver processes it and delivers it to the network layer. It then sends an
acknowledgement back to the sender.
Sender Site Algorithm of Simplex Stop – and – Wait Protocol for Noiseless Channel
begin
canSend = True; //Allow the first frame to be sent
while (true) //check repeatedly
do
Wait_For_Event(); //wait for availability of packet
if ( Event(Request_For_Transfer) AND canSend) then
Get_Data_From_Network_Layer();
Make_Frame();
Send_Frame_To_Physical_Layer();
canSend = False;
else if ( Event(Acknowledgement_Arrival)) then
Receive_ACK();
canSend = True;
end if
end while
end
Receiver Site Algorithm of Simplex Stop – and – Wait Protocol for Noiseless Channel
begin
while (true) //check repeatedly
do
Wait_For_Event(); //wait for arrival of frame
if ( Event(Frame_Arrival) then
Receive_Frame_From_Physical_Layer();
Extract_Data();
Deliver_Data_To_Network_Layer();
Send_ACK();
end if
end while
end
Flow Diagram
The following flow diagram depicts communication via simplex stop – and – wait protocol for
noiseless channel:
Simplex Stop – and – Wait protocol for noisy channels is data link layer protocol for data
communications with error control and flow control mechanisms. It is popularly known as Stop – and
–Wait Automatic Repeat Request (Stop – and –Wait ARQ) protocol. It adds error control facilities to
Stop – and – Wait protocol.
This protocol takes into account the facts that the receiver has a finite processing speed and that
frames may get corrupted while transmission. If data frames arrive at the receiver’s end at a rate
which is greater than its rate of processing, frames can be dropped out. Also, frames may get
corrupted or entirely lost when they are transmitted via network channels. So, the receiver sends an
acknowledgment for each valid frame that it receives. The sender sends the next frame only when it
has received a positive acknowledgment from the receiver that it is available for further data
processing. Otherwise, it waits for a certain amount of time and then resends the frame.
Design
● Sender Site − At the sender site, a field is added to the frame to hold a sequence number. If
data is available, the data link layer makes a frame with the certain sequence number and sends it.
The sender then waits for the arrival of acknowledgement for a certain amount of time. If it receives a
positive acknowledgment for the frame with that sequence number within the stipulated time, it sends
the frame with the next sequence number. Otherwise, it resembles the same frame.
● Receiver Site − The receiver also keeps a sequence number of the frames expected for arrival.
When a frame arrives, the receiver processes it and checks whether it is valid or not. If it is valid and
its sequence number matches the sequence number of the expected frame, it extracts the data and
delivers it to the network layer. It then sends an acknowledgement for that frame back to the sender
along with its sequence number.
Sender Site Algorithm of Simplex Stop – and – Wait Protocol for Noisy Channel
begin
SeqNo = 0; // Initialize sequence number of outbound frame
canSend = True; //Allow the first frame to be sent
while (true) //check repeatedly
do
Wait_For_Event(); //wait for availability of packet
if ( Event(Request_For_Transfer) AND canSend) then
Get_Data_From_Network_Layer();
frame = Make_Frame(SeqNo);
Store_Copy_Frame([Link]);
Send_Frame_To_Physical_Layer([Link]);
Start_Timer([Link]);
SeqNo = SeqNo + 1;
canSend = False;
else if ( Event(Acknowledgement_Arrival)) then
Receive_ACK();
if ( ACK_No = SeqNo ) then
Stop_Timer ([Link]);
canSend = True;
end if
else if ( Event( Timer > Max_time)) then
Resend_Frame_To_Physical_Layer([Link]-1);
Start_Timer([Link]-1);
end if
end while
end
Receiver Site Algorithm of Simplex Stop – and – Wait Protocol for Noisy Channel
begin
RSeqNo = 0; // Initialise sequence number of expected frame
while (true) //check repeatedly
do
Wait_For_Event(); //wait for arrival of frame
if ( Event(Frame_Arrival) then
Receive_Frame_From_Physical_Layer();
if ( Corrupted ( [Link] )
doNothing();
else if ( [Link] = RSeqNo ) then
Extract_Data();
Deliver_Data_To_Network_Layer();
RSeqNo = RSeqNo + 1;
end if
Send_ACK(ACKframe[RSeqNo]);
end if
end while
end
Flow Diagram
The following flow diagram depicts communication via simplex stop – and – wait ARQ protocol for
noisy channel −
Sliding Window Protocol
The Stop and Wait ARQ offers error and flow control, but may cause big performance issues
as the sender always waits for acknowledgement even if it has the next packet ready to send.
Consider a situation where you have a high bandwidth connection and propagation delay is
also high (you are connected to some server in some other country through a high-speed
connection), you can’t use this full speed due to limitations of stop and wait.
Sliding Window protocol handles this efficiency issue by sending more than one packet at a
time with a larger sequence number. The idea is the same as pipelining in architecture.
Few Terminologies :
Transmission Delay (Tt) – Time to transmit the packet from host to the outgoing link. If B is
the Bandwidth of the link and D is the Data Size to transmit
Tt = D/B
Propagation Delay (Tp) – It is the time taken by the first bit transferred by the host onto the
outgoing link to reach the destination. It depends on the distance d and the wave propagation
speed s (depends on the characteristics of the medium).
Tp = d/s
Efficiency – It is defined as the ratio of total useful time to the total cycle time of a packet. For
stop and wait protocol,
Total cycle time = Tt(data) + Tp(data) +
Tt(acknowledgement) + Tp(acknowledgement)
= Tt(data) + Tp(data) + Tp(acknowledgement)
= Tt + 2*Tp
Since acknowledgements are very less in size, their transmission delay can be neglected.
Efficiency = Useful Time / Total Cycle Time
= Tt/(Tt + 2*Tp) (For Stop and Wait)
= 1/(1+2a) [ Using a = Tp/Tt ]
Capacity of link – If a channel is Full Duplex, then bits can be transferred in both the
directions and without any collisions. Number of bits a channel/Link can hold at maximum is
its capacity.
Capacity = Bandwidth(B) * Propagation(Tp)
Concept Of Pipelining
In Stop and Wait protocol, only 1 packet is transmitted onto the link and then the sender waits
for acknowledgement from the receiver. The problem in this setup is that efficiency is very
less as we are not filling the channel with more packets after the 1st packet has been put onto
the link. Within the total cycle time of Tt + 2*Tp units, we will now calculate the maximum
number of packets that sender can transmit on the link before getting an acknowledgement.
In Tt units ----> 1 packet is Transmitted.
In 1 unit ----> 1/Tt packet can be Transmitted.
In Tt + 2*Tp units -----> (Tt + 2*Tp)/Tt
packets can be Transmitted
------> 1 + 2a [Using a = Tp/Tt]
After we
have received the Ack for packet 0, window slides and the next packet can be assigned
sequence number 0. We reuse the sequence numbers which we have acknowledged so that
header size can be kept minimum as shown in the diagram given below.
Sliding Window Protocol is actually a theoretical concept in which we have only talked
about what should be the sender window size (1+2a) in order to increase the efficiency of
stop and wait arq. Now we will talk about the practical implementations in which we take care
of what should be the size of the receiver window. Practically it is implemented in two
protocols namely :
1. Go Back N (GBN)
2. Selective Repeat (SR)
In this article, we will explain you about the first protocol which is GBN in terms of three main
characteristic features and in the next part we will be discussing SR as well as comparison of
both these protocols
It is IN itself. If we say the protocol is GB10, then Ws = 10. N should be always greater than 1
in order to implement pipelining. For N = 1, it reduces to the Stop and Wait protocol.
WR is always 1 in GBN. Now what exactly happens in GBN, we will explain with the help of an
example. Consider the diagram given below. We have a sender window size of 4. Assume
that we have lots of sequence numbers just for the sake of explanation. Now the sender has
sent the packets 0, 1, 2 and 3. After acknowledging the packets 0 and 1, receiver is now
expecting packet 2 and sender window has also slided to further transmit the packets 4 and 5.
Now suppose the packet 2 is lost in the network, Receiver will discard all the packets which
the sender has transmitted after packet 2 as it is expecting sequence number 2. On the
sender side for every packet sent there is a time out timer which will expire for packet number
2. Now from the last transmitted packet 5 sender will go back to the packet number 2 in the
current window and transmit all the packets till packet number 5. That’s why it is called Go
Back N. Go back means sender has to go back N places from the last transmitted packet in
the unacknowledged window and not from the point where the packet is lost.
Acknowledgements
There are 2 kinds of acknowledgements namely:
● Cumulative Ack: One acknowledgement is used for many packets. The main
advantage is less traffic. A disadvantage is less reliability as if one ack is the loss that would
mean that all the packets sent are lost.
● Independent Ack: If every packet is going to get acknowledgement independently.
Reliability is high here but a disadvantage is that traffic is also high since for every packet we
are receiving independent ack.
GBN uses Cumulative Acknowledgement. At the receiver side, it starts an
acknowledgement timer whenever the receiver receives any packet which is fixed and when it
expires, it is going to send a cumulative Ack for the number of packets received in that
interval of timer. If the receiver has received N packets, then the Acknowledgement number
will be N+1. Important point is that the Acknowledgement timer will not start after the expiry of
the first timer but after the receiver has received a packet.
Time out timer at the sender side should be greater than the Acknowledgement timer.
Relationship Between Window Sizes and Sequence Numbers
We already know that sequence numbers required should always be equal to the size of
window in any sliding window protocol.
Minimum sequence numbers required in GBN = N + 1
Bits Required in GBN = ceil(log2 (N + 1))
Retransmission requests :
● Implicit – The receiver acknowledges every good packet, packets that are not ACKed
before a time-out are assumed lost or in [Link] that this approach must be used to be
sure that every packet is eventually received.
● Explicit – An explicit NAK (selective reject) can request retransmission of just one
packet. This approach can expedite the retransmission but is not strictly needed.
● One or both approaches are used in practice.
Selective Repeat Protocol (SRP) : This protocol(SRP) is mostly identical to GBN protocol,
except that buffers are used and the receiver, and the sender, each maintains a window of
size. SRP works better when the link is very unreliable. Because in this case, retransmission
tends to happen more frequently, selectively retransmitting frames is more efficient than
retransmitting all of them. SRP also requires a full-duplex link. backward acknowledgements
are also in progress.
● Sender’s Windows ( Ws) = Receiver’s Windows ( Wr).
● Window size should be less than or equal to half the sequence number in SR protocol.
This is to avoid packets being recognized incorrectly. If the size of the window is greater than
half the sequence number space, then if an ACK is lost, the sender may send new packets
that the receiver believes are retransmissions.
● Senders can transmit new packets as long as their number is with W of all unACKed
packets.
● Sender retransmits un-ACKed packets after a timeout – Or upon a NAK if NAK is
employed.
● Receiver ACKs all correct packets.
● Receiver stores correct packets until they can be delivered in order to the higher layer.
● In Selective Repeat ARQ, the size of the sender and receiver window must be at most
one-half of 2^m.
Figure – the sender only retransmits frames, for which a NACK is receivedEfficiency of
Selective Repeat Protocol (SRP) is same as GO-Back-N’s efficiency :
Efficiency = N/(1+2a)
Where a = Propagation delay / Transmission delay
Buffers = N + N
Sequence number = N(sender side) + N ( Receiver Side)
Examples of Data Link Layer Protocols
Data Link Layer protocols are generally responsible to simply ensure and confirm that the bits
and bytes that are received are identical to the bits and bytes being transferred. It is basically
a set of specifications that are used for implementation of a data link layer just above the
physical layer of the Open System Interconnections (OSI) Model.
Some Common Data Link Protocols :
There are various data link protocols that are required for Wide Area Network (WAN) and
modem connections. Logical Link Control (LLC) is a data link protocol of Local Area Network
(LAN). Some of data link protocols are given below :
SLIP is generally an older protocol that is just used to add a framing byte at the end of an IP
packet. It is basically a data link control facility that is required for transferring IP packets
usually among Internet Service Providers (ISP) and a home user over a dial-up link. It is an
encapsulation of the TCP/IP especially designed to work with over serial ports and several
router connections simply for communication. It has some limitations like it does not provide
mechanisms such as error correction or error detection.
PPP is a protocol that is basically used to provide the same functionality as SLIP. It is the
most robust protocol that is used to transport other types of packets also along with IP
Packets. It can also be required for dial-up and leased router-router lines. It basically provides
a framing method to describe frames. It is a character-oriented protocol that is also used for
error detection. It is also used to provides two protocols i.e. NCP and LCP. LCP is used for
bringing lines up, negotiation of options, bringing them down whereas NCP is used for
negotiating network-layer protocols. It is required for the same serial interfaces as that of
HDLC.
It was originally developed and created by IEEE 802.2. It is also used to provide HDLC style
services on LAN (Local Area Network). LCP is basically a PPP protocol that is used for
establishing, configuring, testing, maintenance, and ending or terminating links for
transmission of data frames.
LAP protocols are basically data link layer protocols that are required for framing and
transferring data across point-to-point links. It also includes some reliability service features.
There are basically three types of LAP i.e. LAPB (Link Access Procedure Balanced), LAPD
(Link Access Procedure D-Channel), and LAPF (Link Access Procedure Frame-Mode Bearer
Services). It actually originated from IBM SDLC, which is being submitted by IBM to the ISP
simply for standardization.