You are on page 1of 18

JSS Mahavidyapeetha

JSS Academy of Technical Education


Kengeri-Uttarahalli Main Road, Bangalore-560060

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

COURSE NAME: DATA COMMUNICATION: 17CS46

TOPIC: FLOW CONTROL METHODS

Prepared by:
Srinandan A B Siddhant Singh Sri Hari K R Suhas M Suyog P
Shubham Sahu Sowmya A R Suchitra S Sunidhi A G T
Rachana

Semester / Branch: 4th semester, CSE


IMPLEMENTATION OF FLOW CONTROL
METHODS IN C/C++
FLOW CONTROL:
It is the set of procedures used to restrict the amount of data that the sender
can send before waiting for acknowledgement.

The data link layer can combine framing, flow control, and error control to
achieve the delivery of data from one node to another, these are done by
certain protocols
They are:
For noiseless channel: 1) Simplest protocol
2)Stop and wait
For noisy channel: 1)Stop and wait
2)Go-back N
3)Selective Repeat

The protocols we discuss here and those used in real life are different, as we
discuss protocols are unidirectional (data frames travel one node called sender
to another node called receiver). But in real life, data link protocols are
implemented as bidirectional (data flows in both directions).
•Simplest Protocol is one that has no flow or error control and
it is a unidirectional protocol in which data frames are
travelling in only one direction-from the sender to receiver.

•We assume that the receiver can immediately handle any


frame it receives with a processing time that is small enough
to be negligible.

•The data link layer of the receiver immediately removes the


header from the frame and hands the data packet to its network
layer, which can also accept the packet immediately.
1.) Here the sender A will keep on sending frames without
maintaining flow control or error control.
2.) As shown above three frames are send already while receiver B is
processing first frame.
3.) Sender's work is to get data, make frame and send frame.
4.) Receiver's work is receive frame, extract data and deliver data.
DESIGN

• The sender site cannot send a frame until its network layer has a data packet to
send. The receiver site cannot deliver a data packet to its network layer until a
frame arrives.
SENDER SIDE ALGORITHM

RECEIVER SIDE ALGORITHM


 Stop and Wait
Protocol uses
both flow and
error control.
In this
protocol, the
sender sends
one frame at a
time and waits
for an
acknowledge
before sending
the next one.
 #include<stdio.h>
 #include<conio.h>
 #include<stdlib.h>
 void main()
 {
int i,j,noframes,x,x1=10,x2;
 clscr();
 for(i=0;i<200;i++)
 rand();
 noframes=rand()/200;
 i=1;
 j=1;
 noframes=noframes/8;
 printf("\n number of frames is %d",noframes);
 getch();
 while(noframes>0)
 {
 printf("\n sending frame %d",i);
 srand(x1 ++)
 x=rand()%10;
 if(x%2==0)
 {
 for(x2=1;x2<2;x2++)
 {
printf("waiting for %d sec\n",x2);
 sleep(x2);
 }
 printf("\n sending frame %d",i);
 srand(x1 ++)
 x=rand()%10;
 }
 printf("\n ack for frame %d ",j);
 noframes=1;
 i++;
 j++;
 }
 printf("\n end of stop n wait protocol");
 getch();
 }
 No of frames is 6
 Sending frame 1
 Acknowledgement for frame 1
 Sending frame 2
 Acknowledgement for frame 2
 Sending frame 3
 Acknowledgement for frame 3
 Sending frame 4
 Acknowledgement for frame 4
 Sending frame 5
 Waiting for 1 second
 Retransmitting frame 5
 Acknowledgement for frame 5
 Sending frame 6
 Waiting for 1 second
 Sending frame 6
 Acknowledgement for frame 6
 End of Stop and Wait Protocol
DEFINITION
 Go-Back N ARQ is a specific instance of the automatic repeat request (ARQ) protocol , in
which the sending process continues to send a number of frames specified by a window size
even without receiving an acknowledgement(ACK) packet from the receiver.
 GBN is a practical approach of sliding window protocol.
Receiver sliding window
 Size of the window at the receiving site is always 1 in this protocol.
 Receiver is always looking for a specific frame to arrive in a specific order.
 Any frame arriving out of order is discarded and needs to be resent.
 Receiver sends positive ACK if a frame arrived safe in order.
 The silence of receiver causes the timer of the unacknowledged frame to expire.
Then the sender resends all the frames, beginning with the one with the expired
timer.

Normal Operation Data Packet is lost


Program
#include<iostream>

using namespace std;

int main()
{
int w,i,f,frames[50];

cout<<"Enter window size: ";


cin>>w;

cout<<"\nEnter number of frames to transmit: ";


cin>>f;

cout<<"\nEnter "<<f<<" frames: ";

for(i=1;i<=f;i++)
cin>>frames[i];

cout<<"\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)\n\n";
cout<<"After sending "<<w<<" frames at each stage sender waits for acknowledgement sent by the receiver\n\n";

for(i=1;i<=f;i++)
{
if(i%w==0){
cout<<frames[i]<<"\n";
cout<<"Acknowledgement of above frames sent is received by sender\n\n";
}
else
cout<<frames[i]<<" ";
}

if(f%w!=0)
cout<<"\nAcknowledgement of above frames sent is received by sender\n";

return 0;
}
SELECTIVE REPEAT PROTOCOL:

DEFINITION:
Selective Repeat protocol is a specific instance of the automatic repeat
request protocol (ARQ) used to solve sequence number dilemma in communications.
Here the sender sends a number of frames specified by a window size even without the
need to wait for individual acknowledgement (ACK) from the receiver as in Go-Back-N
protocol.
Selective Repeat Protocol Program in C:
#include<stdio.h>

int main()
{
int w,i,f,frames[50];
printf("Enter window size: ");
scanf("%d",&w);
printf("\nEnter number of frames to transmit: ");
scanf("%d",&f);
printf("\nEnter %d frames: ",f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}
 Go back N is more often used than other protocols.
 SR protocol is less used because of its complexity.
 Stop and Wait ARQ is less used because of its low efficiency.
 Depending on the context and resources availability, Go back
N or Selective Repeat is employed.
 Selective Repeat and Stop and Wait ARQ are similar in terms
of retransmissions.
 Go back N and Selective Repeat are similar in terms of
efficiency if sender window sizes are same.
 SR protocol may be considered as a combination of
advantages of Stop and Wait ARQ and Go back N.
 SR protocol is superior to other protocols but because of its
complexity, it is less used.
TECHNOLOGIES THAT USE FLOW
CONTROL
 Software flow control
 Computer networking
 Traffic contract
 Congestion control
 Teletraffic engineering in broadband networks
 Teletraffic engineering
 Ethernet flow control
 Atm

You might also like