Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

PERFORMANCE ANALYSIS OF FLOW CONTROL MECHANISM

AIM:

To implement flow control mechanism such as Stop and Wait, Go Back – N and Selective
Reject and to verify their performance in Matlab.

ALGORITHM:

STOP AND WAIT:

1. Start.
2. Enter the number of frames to be transmitted.
3. Sender transmits the first frame and waits for the acknowledgement from the receiver for
the transmitted time.
4. The receiver sends the acknowledgement (ACK) to the sender.
5. If the sender receives the ACK, it transmits the next frame.
6. Else the sender waits until the timer expires, and re-transmits the frame again.
7. The above step is followed until all the frames get transmitted.
8. Stop the program.

GO BACK N:

1. Start.
2. Enter the number of frames to be transmitted.
3. Enter the window size n.
4. The sender transmits the group of frames and each frame is labeled with a sequence
number.
5. If the receiver receives the frames intact then the receiver sends positive acknowledgement.
6. Else the receiver sends the negative acknowledgement for the frame from which the sender
have to re-transmit the frame in sequence.
7. The step is followed until all the frames get transmitted.
8. Stop the program.

SELECTIVE REJECT:
1. Start.
2. Enter the number of frames to be transmitted.
3. Enter the window size n.
4. The sender transmits the group of frames and each frame is labeled with a sequence
number.
5. If the receiver receives the frames intact then the receiver sends positive acknowledgement.
6. Else the receiver sends the negative acknowledgement for the particular frame which is lost
or damaged.
7. Hence the sender re-transmits that particular frame and sends the next group of frames.
8. The step is followed until all the frames get transmitted.
9. Stop the program.
PROGRAM:
STOP AND WAIT:
clc;
clear all;
close all;
warning('off','all');
n=input('enter the number of transmitting frames');
frame=1;
p=input('enter the positive acknowledgement');
N=input('enter the negative acknowledgement');
m=input('maximum no of frames');
t=input('enter the time out');
while frame<=n
fprintf('\ntransmitting frame is %d\n',frame);
s=randint(1,1,m);
disp('the random integer is ');
disp(s);
if s<t
fprintf('timeout \n RE')
elseif s>=p
fprintf('positive acknowledgemnt is recieved');

frame=frame+1;
else
fprintf('negative acknowledgement is recieved %d',frame);
end
end
THEORY:

FLOW CONTROL:

It refers to set of procedure involved in data link layer, to know the number of frames that
can be sent to the receiver without overwhelming to the receiver.

FLOW CONTROL PROTOCOL:

1. Stop and Wait


2. Sliding Window
 Go Back N
 Selective Reject

STOP AND WAIT:

It is simplest algorithm and useful protocol in noiseless condition. The sender transmits one
frame at a time and waits for the acknowledgement from the receiver. If the receiver sends the
acknowledgement then the sender transmits the next frame else the sender waits until the timer get
expires and re-transmit the frame. Here the sender should always have the copy of the transmitted
frames, till it receives the acknowledgement from the receiver.

ADVANTAGE:

 It is the simplest algorithm.


 No sequence is needed.

DISADVANTAGE:

 Resource utilization is more.


 Transmission time is huge.
OUTPUT:
SLIDING WINDOW:

Multiple frames are transmitted at a time. The sequence of the frame should be given. The
window size must be same at the receiver and the sender.

There are three possibilities

1. Lost data frame


2. Damaged data frame
3. Lost ACK

For the above possibilities, the sender should always preserve the copies of transmitted frames and
activates the timers and wait for the acknowledgement. If there is no response in the form of
NAK/ACK the sender re-transmits all the frames. The receiver should send the damage frame (NAK)
or the next expected frame (ACK) and should be aware of the status of lost/received frames. It needs
to check whether the frame received is duplicate or not. If the frame received is duplicate then
discard it.

GO BACK N:

The group of frames is transmitted by the sender and it wait for the acknowledgement. If one of the
frames is erroneous in the group of frames then the remaining frames are discarded. Thus the
sender re-transmit the frames from the erroneous frame onwards.
PROGRAM:
GO BACK N:
clc;
clear all;
close all;
warning('off','all');
n=input('enter the number of transmitting frames');
w=input('enter the window size');
frame=1;
count=0;
while frame<=n
for i=1:w
if (frame<=n && frame<count)
fprintf('re-transmitting frame %d\n', frame);
frame=frame+1;
elseif(frame<=n && frame>=count)
fprintf('transmitting frame %d \n',frame);
frame=frame+1;
s=randint(1,1,15);
disp('the random integer is');
disp(s);
end
end
y=input('enter the frame that has recieved negative frame or
enter 0 for all frames received positive acknowledgement');
if(y~=0)
count=frame;
frame=y;
end
end

OUTPUT:
ADVANTAGE:

 One ACK can acknowledge more than one frames.


 The sender can send many frames at a time.
 Efficiency is more.

DISADVANTAGE:

 Resource utilization is more.

SELECTIVE REPEAT:

The sender sends the group of frames and waits for the acknowledgement. If the particular
frame is erroneous or damaged only that particular frame is discarded while remaining frames are
not discarded. The receiver sends the negative acknowledgement for that frame. The sender re-
transmits that particular frame along with the next group of frames.

ADVANTAGE:

 Wastage of resource is reduced.

DISADVANTAGE:

 It is a complicated mechanism.
PROGRAM:
SELECTIVE REPEAT:
clc;
clear all;
close all;
n=input('enter the number of frames to be transmittted:');
w=input('enter the window size:');
x=1;
z='';
for i=1:w
fprintf('transmitting frame %d /n',x);
x=x+1;
end
y=input('enter the number of negatively acknowledged frames or /n
enter 0 if all the transmitted frames are positively
acknowledged:');
while 1
if y~=0&&x~=n+1
for a=1:y
z(a)=input('enter the negatively acknowledged frame:');
end
for a=1:y
fprintf('retransmitting frame %d\n',z(a));
end
for i=y+1:w
if x<=n
fprintf('transmitting frame %d /n',x);
x=x+1;
else
break;
end
end
y=input('enter the number of negatively acknowledged frames or
/n enter 0 if all the transmitted frames are positively
acknowledged:');
elseif y==0&&x~=n+1
for i=1:w
if x<=n
fprintf('transmitting frame %d\n',x);
x=x+1;
else
break;
end
end
y=input('enter the number of negatively acknowledged frames
or /n enter 0 if all the transmitted frames are positively
acknowledged:');
elseif y~=0&&x==n+1
for a=1:y
z(a)=input('enter the negatively acknowledged frame:');
end
for a=1:y
fprintf('retransmitting frame %d\n',z(a));

end
y=input('enter the number of negatively acknowledged
frames or /n enter 0 if all the transmitted frames are positively
acknowledged:');
elseif y==0&&x~=n+1
fprintf('all frames are transmitted successfully')';
break;
else
break;
end
end

OUTPUT:
RESULT:

Thus the flow control mechanism have been implemented and its performance is verified.

You might also like