Selective
Repeat Protocol [MatlAb]
clc;
clear
all;
n=input('Enter the
number of frames: ');
w=input('Window
Size: ');
pt=w+1;
flag=0;
ext=0;
flag1=0;
flag2=0;
a=1:n;
for
i=1:w
fprintf('Frame %d
Transferred\n',a(i));
end
while
flag==0
s=randint(1,1,10);
if
s>3
fprintf('PAK of
frame %d received\n',a(pt-w));
else
fprintf('NAK of
frame %d received\n',a(pt-w));
ext=ext+1;
for
i=n+ext:-1:pt+1
a(i)=a(i-1);
end
a(pt)=a(pt-w);
end
fprintf('Frame %d
Transferred\n',a(pt));
if
a(pt)==n
flag=1;
end
pt=pt+1;
end
k=pt-w;
while
flag2==0
test=randint(1,1,[1
7]);
if
flag1==1
fprintf('Frame %d
Transmitted\n',a(k));
flag1=0;
end
if
test>3
fprintf('PAK of
frame %d received\n',a(k));
k=k+1;
else
fprintf('NAK of
frame %d received\n',a(k));
flag1=1;
end
if
k==n+ext+1
flag2=1;
end
end
No comments:
Post a Comment