Você está na página 1de 21

GO BACK N PROTOCOL

clc; clear all; n=input('Number Of Frames: '); w=input('Window Size: '); pt=1; flag=0; flag2=0; a=1:n; while flag==0 if flag2==0 %Transmitting The Frames In A Window for i=1:w fprintf('Frame %d Transmitted\n',a(pt)); pt=pt+1; end flag2=1; end s=randint(1,1,10); if s>3 fprintf('PAK of Frame %d Received\n',a(pt-w)); fprintf('Frame %d Transmitted\n',a(pt)); if a(pt)==n flag=1; end pt=pt+1; else fprintf('NAK Of Frame %d Received\n',a(pt-w)); for j=0:w-1 fprintf('Frame %d Discarded\n',a(pt-w+j)); end pt=pt-w; flag2=0; end end %Last 'W' Frames are dealt seperately i=n-w+1; while (i<=n) s=randint(1,1,10); if s>4 fprintf('PAK of Frame %d Received\n',a(i)); i=i+1; else fprintf('NAK of Frame %d Received \n',a(i)); for j=i:n

fprintf('Frame %d Discarded\n',a(j)); end for k=i:n fprintf('Frame %d Transmitted\n',a(k)); end end end

BIT STUFFING
clc; clear all; msg=input('Input Message Binary Bit Stream: '); count=0; stuffcount=0; [M N]=size(msg); for j=1:N-5+stuffcount for i=j:j+5 if msg(i)==1 count=count+1; else count=0; break; end end if count==6 msg=[msg(1:j+4) 0 msg(j+5:end)]; count=0; stuffcount=stuffcount+1; end end fprintf('Stream after the bit is stuffed:'); disp(msg);

M/M/1 QUEUING MODEL


clc; clear all; arrival_rate = input('Enter the arrival rate : '); service_rate = input('Enter the service rate : '); error_rate = input('Enter the max acceptable packet loss : '); timeslots = input('Enter the number of timeslots : '); t = 1:timeslots; tarr = zeros (1,timeslots); tser = zeros (1,timeslots); tarr(1,:) = poissrnd( arrival_rate, 1, timeslots); tser(1,:) = poissrnd( service_rate, 1, timeslots); %Timeslot vs Packet loss n = zeros (1,timeslots); for j = 1:timeslots if ( tarr(1,j) > tser(1,j) ) n(1,j) = ( tarr(1,j) - tser(1,j) ) ; end end bar (t,n,.01); xlabel ('Timeslot'); ylabel ('Packet loss'); disp ('The max packet loss is :'); disp (max(n)); disp ('The average packet loss before buffering is :'); avg = mean(n); disp (avg); %Buffer size vs Packet loss buff = 0; count = 1; avg_loss(1,count) = avg ; buffer_size(1,count) = buff; while (avg > error_rate) count = count+1; buff = buff+1; tser = tser+1; for j = 1:timeslots if (n(1,j) > 0) n(1,j) = (tarr(1,j) - tser(1,j)); end end avg = mean(n); avg_loss (1,count) = avg; buffer_size (1,count) = buff; end

disp('The maximum packet loss after buffering is :'); disp(avg); disp('The maximum buffer size for the given error rate is :'); disp(buff); figure(2); line (buffer_size,avg_loss); xlabel('Buffer size'); ylabel('Packet loss');

M/G/1 QUEUING MODEL


clc; clear all; arrival_rate=input('Enter the Data Arrival Rate: '); service_rate=input('Enter the Data Service Rate: '); error_rate=input('Enter the maximum acceptable Packet Loss Rate: '); timeslots=100; t=1:timeslots; tarr=zeros(1,timeslots); tser=zeros(1,timeslots); tarr(1,:)=poissrnd((arrival_rate),1,timeslots); tser1(1,:)=exprnd((service_rate),1,timeslots); tser=round(tser1); %Time Slots Vs Packet Loss n=zeros(1,timeslots); for j=1:timeslots if (tarr(1,j)>tser(1,j)) n(1,j)=tarr(1,j)-tser(1,j); end end bar(t,n,0.01); xlabel('Time Slots'); ylabel('Packet Loss'); disp('The maximum Packet Loss is: '); disp(max(n)); disp('The Average Packet Loss before Buffering: '); avg=mean(n); disp(avg); %Buffer Size Vs Packet Loss buff=0; count=1; avg_loss (1,count)=avg; buffer_size (1,count)=buff; while (avg>error_rate) count=count+1; buff=buff+1; tser=tser+1; for j=1:timeslots if (n(1,j)>0) n(1,j)=tarr(1,j)-tser(1,j); end end avg=mean(n); avg_loss(1,count)=avg;

buffer_size(1,count)=buff; end disp('The maximum Packet Loss after Buffering is: '); disp(max(n)); disp('The Average Packet Loss after Buffering is: '); disp(avg);

disp('The maximum Buffer Size for the given Error Rate: '); disp(buff); figure(2); line(buffer_size,avg_loss); xlabel('Buffer Size'); ylabel('Packet Loss');

G/G/1 QUEUING MODEL


clc; clear all; arrival_rate=input('Enter the Data Arrival Rate: '); service_rate=input('Enter the Data Service Rate: '); error_rate=input('Enter the maximum acceptable Packet Loss Rate: '); timeslots=100; t=1:timeslots; tarr=zeros(1,timeslots); tser=zeros(1,timeslots); tarr1(1,:)=normrnd((arrival_rate),5,1,timeslots); tarr=round(tarr1); tser1(1,:)=exprnd((service_rate),1,timeslots); tser=round(tser1); %Time Slots Vs Packet Loss n=zeros(1,timeslots); for j=1:timeslots if(tarr(1,j)>tser(1,j)); n(1,j)=tarr(1,j)-tser(1,j); end end bar(t,n,0.01); xlabel('Time Slots'); ylabel('Packet Loss'); disp('The maximum Packet Loss is: '); disp(max(n)); disp('The Average Packet Loss before Buffering is: '); avg=mean(n); disp(avg); %Buffer Size Vs Packet Loss buff=0; count=1; avg_loss(1,count)=avg; buffer_size(1,count)=buff; while(avg>error_rate) count=count+1; buff=buff+1; tser=tser+1; for j=1:timeslots if n(1,j)>0 n(1,j)=tarr(1,j)-tser(1,j); end end avg=mean(n); avg_loss(1,count)=avg;

buffer_size(1,count)=buff; end disp('The maximum Packet Loss after Buffering is: '); disp(max(n)); disp('The Average Packet Loss after Buffering is: '); disp(avg); disp('The maximum Buffer Size for the given Error Rate is: '); disp(buff); figure(2); line(buffer_size,avg_loss); xlabel('Buffer Size'); ylabel('Packet Loss');

VOICE TRAFFIC
clc; clear all; use=input('Enter the no of users: '); ts=input('Enter the no. of time slots: '); on=0.35; ton=zeros(use,ts); n=ton; for i=1:use for j=1:ts ton(i,:)=poissrnd((on*10),1,ts); if (ton(i,j)>=3.5) n(i,j)=1; end end end voice=64000*n; % time slot vs bw d=sum(voice); figure(1); bar(d); xlabel('Timeslot'); ylabel('Bandwidth(bps)'); % time slots vs error rate e=zeros(1,ts); bm=1540000; for i=1:ts if d(i) > bm e(i)=d(i)-bm; end end figure(2); bar(e); xlabel('Timeslots'); ylabel('Error rate (bps)'); avg=sum(e')/ts; ber=avg/bm; buff=0; disp('Average bit error rate without buffers:'); disp(ber); while ber > 1e-6 buff=buff+10; bm=bm+10; for i=1:ts if e(i)>0

e(i)=d(i)-bm; end end s=sum(e'); ber=s/(ts*bm); end disp('BER with buffer:'); disp(ber); disp('Optimum buffer size'); disp(buff);

VIDEO TRAFFIC
clc; clear all; use=input('Enter The Number Of Users: '); ts=input('Enter The Number Of Time Slots: '); on=0.35; ton=zeros(use,ts); n=ton; for i=1:use for j=1:ts ton(i,:)=poissrnd((on*10),1,ts); if(ton(i,j)>=3.5) n(i,j)=1; end end end test=randint(use,ts,[1,1000]); data=n; for i=1:use for j=1:ts if n(i,j)==1 if test(i,j)>=1 && test(i,j)<=980 data(i,j)=64000; else data(i,j)=384000; end end end end %Time Slot Vs Bandwidth d=sum(data); figure(1); bar(d); xlabel('Time Slot'); ylabel('Bandwidth (bps)'); %Time Slots Vs Error Rate e=zeros(1,ts); bm=1540000; for i=1:ts if d(i)>bm e(i)=d(i)-bm; end end figure(2); bar(e);

xlabel('Time Slot'); ylabel('Error Rate (bps)'); avg=sum(e)/ts; ber=avg/bm; buff=0; disp('Average Bit Error Rate without Buffering: '); disp(ber); while ber>1e-6 buff =buff+10; bm=bm+10; for i=1:ts if e(i)>0 e(i)=d(i)-bm; end end s=sum(e); ber=s/(ts*bm); end disp('Bit Error Rate with Buffer: '); disp(ber); disp('Optimum Buffer Size: '); disp(buff);

DATA TRAFFIC
clear all; clc; use=input('Enter the no. of users: '); ts=input('Enter the no. of time slots: '); on=0.35; ton=zeros(use,ts); n=ton; for i=1:use for j=1:ts ton(i,:)=poissrnd((on*10),1,ts); if (ton(i,j)>=3.5) n(i,j)=1; end end end test=randint(use,ts,[1,1000]); data=n; for i=1:use for j=1:ts if n(i,j)==1 if test(i,j)>=1 & test(i,j)<=980 data(i,j)=64000; elseif test(i,j)>980 & test(i,j)<=990 data(i,j)=128000; elseif test(i,j)>990 & test(i,j)<=998 data(i,j)=256000; else data(i,j)=512000; end end end end %timeslot vs bandwidth d= sum(data); figure(1); bar(d); xlabel('Time slot'); ylabel('Bandwidth(bps)'); %timeslot vs error rate e=zeros(1,ts); bm=1540000; for i=1:ts if d(i)>bm e(i)=d(i)-bm;

end end figure(2); bar(e); xlabel('Timeslot'); ylabel('Error rate (bps)'); avg=sum(e')/ts; ber=avg/bm; buff=0; disp('Average bit error rate without buffering'); disp(ber); while (ber)>1e-6 buff=buff+10; bm=bm+10; for i=1:ts if e(i)>0 e(i)=d(i)-bm; end end s=sum(e'); ber=s/(ts*bm); end disp('Bit error rate with buffer'); disp(ber); disp('Optimum buffer size'); disp(buff);

ISDN TRAFFIC
clc; clear all; use=input('Enter the Number of users: '); ts=input('Enter the Number of Time Slots: '); on=0.35; voiceuser=0; datauser=0; voipuser=0; ton=zeros(use,ts); n=ton; for i=1:use for j=1:ts ton(i,:)=poissrnd((on*10),1,ts); if (ton(i,j)>=3.5) n(i,j)=1; end end end userprob=randint(1,use,[1,10]); useriden=ones(1,use); for i=1:use if (userprob(i)>=1 & userprob<=5) useriden(i)=1; voiceuser=voiceuser+1; elseif (userprob(i)>5 & userprob(i)<=8) useriden(i)=2; voipuser=voipuser+1; else useriden(i)=3; datauser=datauser+1; end end newuseriden=sort(useriden); isdn=64000*n; test=randint(voipuser,ts,[1,1000]); for i=voiceuser+1:voipuser+voiceuser for j=1:ts if n(i,j)==1 if test(i-voiceuser,j)>=1 & test(i-voiceuser,j)<=800 isdn(i,j)=64000; else isdn(i,j)=384000; end end

end end test1=randint(datauser,ts,[1,1000]); for i=voiceuser+voipuser+1:use for j=1:ts if n(i,j)==1 if test1(i-(voiceuser+voipuser),j)>=1 & test1(i-(voiceuser+voipuser),j)<=800 isdn(i,j)=64000; elseif test1(i-(voiceuser+voipuser),j)>800 & test1(i-(voiceuser+voipuser),j)<=900 isdn(i,j)=128000; elseif test1(i-(voiceuser+voipuser),j)>900 & test1(i-(voiceuser+voipuser),j)<=950 isdn(i,j)=256000; else isdn(i,j)=512000; end end end end %Time Slots Vs Bandwidth d=sum(isdn); figure(1); bar(d); xlabel('Time Slots'); ylabel('Bandwidth(bps)'); %Time Slots Vs Error Rate e=zeros(1,ts); bm=1984000; for i=1:ts if d(i)>bm e(i)=d(i)-bm; end end figure(2); bar(e); xlabel('Time Slots'); ylabel('Error Rate(bps)'); buff=0; newbw=1984000+buff; prisdn=isdn(1:voiceuser,:); voipsort=isdn(voiceuser+1:voiceuser+voipuser,:); prisdn(voiceuser+1:voiceuser+voipuser,:)=sort(voipsort,1); datasort=isdn(voiceuser+voipuser+1:use,:); prisdn(voiceuser+voipuser+1:use,:)=sort(datasort,1); %To Find How many users go unserved with or without buffer? unservedvoice=zeros(1,ts); unservedvoip=zeros(1,ts);

unserveddata=zeros(1,ts); for i=1:ts j=0; bwalloc=0; while (bwalloc<=newbw & j) j=j+1; bwalloc=bwalloc+prisdn(j,i); end ch=j; if ch unservedvoice(i)=voiceuser-ch; unservedvoip(i)=voipuser; unserveddata(i)=datauser; elseif ch>=(voiceuser) & ch<(voiceuser+voipuser) unservedvoip(i)=voiceuser+voipuser-ch; unserveddata(i)=datauser; elseif ch>=(voipuser+voiceuser) & ch unserveddata(i)=use-ch; end end figure(3); bar(unservedvoice); xlabel('Time Slot'); ylabel('Unserved Voice User'); figure(4); bar(unservedvoip); xlabel('Time Slot'); ylabel('Unserved VOIP User');

figure(5); bar(unserveddata); xlabel('Time Slot'); ylabel('Unserved Data User);

ON OFF TRAFFIC
clc; clear all; x=1:10; t=1:100; on=input('Enter the Average ON Time: '); %Users Vs Average ON Time ton=zeros(10,100); for i=1:10 ton(i,:)=poissrnd((on*10),1,100); end a=ton'; b=mean(a); c=b/1000; figure(1); bar(x,c,0.35); xlabel('Users'); ylabel('Average ON Time'); %Timeslots Vs Number of Users n=zeros(10,100); for i=1:10 for j=1:100 if (ton(i,j)>=4.5) n(i,j)=1; end end end d=sum(n); figure(2); bar(t,d); xlabel('Time Slots'); ylabel('Number of Users'); %Time slots Vs Bandwidth bw=64000*n; for i=1:10 figure(3); subplot(5,2,i); bar(t,bw(i,:),0.2) xlabel('Time Slots'); ylabel('BW Alloted'); end

Você também pode gostar