Networks lab manual ecp62

46
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING EC P62 - COMPUTER NETWORKS LABORATORY Lab Manual EC P62 - COMPUTER NETWORKS LABORATORY 1. Simulation of ON-OFF and voice traffic model a) To simulate the ON-off traffic model and plot the following waveform i. User numbers Vs ON period. ii. Time slot Vs number of users. iii. Time slot Vs bandwidth allotted. b) To simulate voice traffic model and obtain i. Time slot Vs bandwidth plot. ii. Time slot Vs error plot. iii. Average error rate. iv. The optimum buffer size for which error rate will be less than stipulated value. BHARATHIYAR COLLEGE OF ENGINEERING AND TECHNOLOGY

description

Computer network lab manual for pondicherry university

Transcript of Networks lab manual ecp62

Page 1: Networks lab manual ecp62

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EC P62 - COMPUTER NETWORKS LABORATORY

Lab Manual

EC P62 - COMPUTER NETWORKS LABORATORY

1. Simulation of ON-OFF and voice traffic modela) To simulate the ON-off traffic model and plot the following waveformi. User numbers Vs ON period. ii. Time slot Vs number of users.iii. Time slot Vs bandwidth allotted.b) To simulate voice traffic model and obtaini. Time slot Vs bandwidth plot. ii. Time slot Vs error plot.iii. Average error rate.iv. The optimum buffer size for which error rate will be less than stipulated value.

BHARATHIYAR COLLEGE OF ENGINEERING AND TECHNOLOGY

KARAIKAL

Page 2: Networks lab manual ecp62

2. Simulation of data traffic and video traffic modela) To simulate the data traffic and multiple rate video traffic for multiple users and to obtaini. Time slot Vs bandwidth plot. ii. Time slot Vs BER plot.iii. The optimum buffer size for which error rate will be less than stipulatedvalue.

3. Simulation of ISDN traffic modela) To simulate the ISDN traffic model for multiple users and to obtaini. Time slot VS bandwidth plot. ii. Time slot Vs BER plot.iii. Time slot Vs un-served video user. iv. Time slot Vs un-served data user.

4. PN sequence generation and testinga) To generate maximal and non maximal length PN sequence and test its randomnessproperties.

5. M/M/I queuing modela) To simulate M/M/I queuing model and obtaini. Time slot Vs packet loss plot. ii. Maximum and average packet loss without buffer.iii. Buffer size for the given loss. iv. Maximum and average packet loss with buffer.

6. M/G/I and G/G/I queuing model.a) To simulate a M/G/I and G/G/I queuing model and obtaini. Time slot Vs packet loss plot. ii. Maximum average packet loss without buffer.iii. Buffer size for the given loss. iv. Maximum and average packet loss with buffer.

7. Encryption and decryptiona) To simulate and test the following encryption and decryption algorithm.i. Mono alphabetic cipher- caeser cipher.ii. Poly alphabetic cipher- Trithemius key, Vigenere key, Vigenere plain andcipher key.iii. RSA with and without digital signature.

8. Flow controla) To simulate and testi. Stop and wait protocol ii. Go back N protocol iii. Selective repeat protocol

9. Error control protocola) To simulate and testi. Cyclic redundancy check ii. Hamming code

10. Routing algorithmsa) To simulate and testi. Shortest path routing algorithm ii. Hierarchical routing algorithm

11. Generation of PDFa) To study, generate and trace the following PDFi. Gaussian distribution ii. Uniform distribution iii. Exponential distributioniv. Rayleigh distribution v. Binomial distribution vi. Negative binomial distribution

vii. Gamma distribution viii. Poisson distribution

12. Wireless LANa) To establish wireless LAN test bed (or) wireless LAN environment and performi. Uni-cast ii. Multicast iii. File transfer protocol

Page 3: Networks lab manual ecp62

Experiment No

Name of the Experiment Page NO

1 Simulation of ON-OFF and voice traffic model

2 Simulation of data traffic and video traffic model

3 Simulation of ISDN traffic model

4 PN sequence generation and testing

5 M/M/I queuing model

6 M/G/I and G/G/I queuing model

7 Encryption and decryption

8 Flow control

9 Error control protocol

10 Routing algorithms

11 Generation of PDF

12 Wireless LAN

Page 4: Networks lab manual ecp62

Exp.No:1 Simulation of ON-OFF and voice traffic modelDate:

Aim:To simulate

a) The ON-off traffic model and plot the following waveformi. User numbers Vs ON period.ii. Time slot Vs number of users.iii. Time slot Vs bandwidth allotted.

b) To simulate voice traffic model and obtaini. Time slot Vs bandwidth plot.ii. Time slot Vs error plot.iii. Average error rate.iv. The optimum buffer size for which error rate will be less than stipulatedValue.

Tool Used:

Matlab Coding:

a) Generation of ON-OFF traffic model clc;clear all;x=1:10;t=1:100;on=input('Enter the Average ON Time: ');%Users Vs Average ON Timeton=zeros(10,100);for i=1:10ton(i,:)=poissrnd((on*10),1,100);enda=ton';b=mean(a);c=b/1000;figure(1);bar(x,c,0.35);xlabel('Users');ylabel('Average ON Time');%Timeslots Vs Number of Usersn=zeros(10,100);for i=1:10for j=1:100if (ton(i,j)>=4.5)n(i,j)=1;endend

Page 5: Networks lab manual ecp62

endd=sum(n);figure(2);bar(t,d);xlabel('Time Slots');ylabel('Number of Users');%Time slots Vs Bandwidthbw=64000*n;for i=1:10figure(3);subplot(5,2,i);bar(t,bw(i,:),0.2)xlabel('Time Slots');ylabel('BW Alloted');end

B) Generation of Voice trafficclc;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:usefor j=1:tston(i,:)=poissrnd((on*10),1,ts);if (ton(i,j)>=3.5)n(i,j)=1;endendendvoice=64000*n;% time slot vs bwd=sum(voice);figure(1);bar(d);xlabel('Timeslot');ylabel('Bandwidth(bps)');% time slots vs error ratee=zeros(1,ts);bm=1540000;for i=1:tsif d(i) > bme(i)=d(i)-bm;endendfigure(2);bar(e);xlabel('Timeslots');

Page 6: Networks lab manual ecp62

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-6buff=buff+10;bm=bm+10;for i=1:tsif e(i)>0e(i)=d(i)-bm;endends=sum(e');ber=s/(ts*bm);enddisp('BER with buffer:');disp(ber);disp('Optimum buffer size');disp(buff);

Output:

Page 7: Networks lab manual ecp62

Exp.No:2 Simulation of data traffic and video traffic modelDate:

Aim:To simulate

a) The data traffic and multiple rate video traffic for multiple users and to obtaini. Time slot Vs bandwidth plot.ii. Time slot Vs BER plot.iii. The optimum buffer size for which error rate will be less than stipulated value.

Tool Used:

Matlab Coding:

Data Traffic modelclear 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:usefor j=1:tston(i,:)=poissrnd((on*10),1,ts);if (ton(i,j)>=3.5)n(i,j)=1;endendendtest=randint(use,ts,[1,1000]);data=n;for i=1:usefor j=1:tsif n(i,j)==1if test(i,j)>=1 & test(i,j)<=980data(i,j)=64000;elseif test(i,j)>980 & test(i,j)<=990data(i,j)=128000;elseif test(i,j)>990 & test(i,j)<=998data(i,j)=256000;elsedata(i,j)=512000;endendend

Page 8: Networks lab manual ecp62

end%timeslot vs bandwidthd= sum(data);figure(1);bar(d);xlabel('Time slot');ylabel('Bandwidth(bps)');%timeslot vs error ratee=zeros(1,ts);bm=1540000;for i=1:tsif d(i)>bme(i)=d(i)-bm;endendfigure(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-6buff=buff+10;bm=bm+10;for i=1:tsif e(i)>0e(i)=d(i)-bm;endends=sum(e');ber=s/(ts*bm);enddisp('Bit error rate with buffer');disp(ber);disp('Optimum buffer size');disp(buff);

Generation of Video trafficclc;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:usefor j=1:ts

Page 9: Networks lab manual ecp62

ton(i,:)=poissrnd((on*10),1,ts);if(ton(i,j)>=3.5)n(i,j)=1;endendendtest=randint(use,ts,[1,1000]);data=n;for i=1:usefor j=1:tsif n(i,j)==1if test(i,j)>=1 && test(i,j)<=980data(i,j)=64000;elsedata(i,j)=384000;endendendend%Time Slot Vs Bandwidthd=sum(data);figure(1);bar(d);xlabel('Time Slot');ylabel('Bandwidth (bps)');%Time Slots Vs Error Ratee=zeros(1,ts);bm=1540000;for i=1:tsif d(i)>bme(i)=d(i)-bm;endendfigure(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-6buff =buff+10;bm=bm+10;for i=1:tsif e(i)>0e(i)=d(i)-bm;endend

Page 10: Networks lab manual ecp62

s=sum(e);ber=s/(ts*bm);enddisp('Bit Error Rate with Buffer: ');disp(ber);disp('Optimum Buffer Size: ');disp(buff);

Output:

Page 11: Networks lab manual ecp62

Exp.No:3 Simulation of ISDN traffic modelDate:

Aim:To simulate the ISDN traffic model for multiple users and to obtain

i. Time slot VS bandwidth plot.ii. Time slot Vs BER plot.iii. Time slot Vs un-served video user.iv. Time slot Vs un-served data user.

Tool Used:

Matlab Coding:

Generation of Integrated (ISDN) traffic Model 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:usefor j=1:tston(i,:)=poissrnd((on*10),1,ts);if (ton(i,j)>=3.5)n(i,j)=1;endendenduserprob=randint(1,use,[1,10]);useriden=ones(1,use);for i=1:useif (userprob(i)>=1 & userprob<=5)useriden(i)=1;voiceuser=voiceuser+1;elseif (userprob(i)>5 & userprob(i)<=8)useriden(i)=2;voipuser=voipuser+1;elseuseriden(i)=3;datauser=datauser+1;endendnewuseriden=sort(useriden);

Page 12: Networks lab manual ecp62

isdn=64000*n;test=randint(voipuser,ts,[1,1000]);for i=voiceuser+1:voipuser+voiceuserfor j=1:tsif n(i,j)==1if test(i-voiceuser,j)>=1 & test(i-voiceuser,j)<=800isdn(i,j)=64000;elseisdn(i,j)=384000;endendendendtest1=randint(datauser,ts,[1,1000]);for i=voiceuser+voipuser+1:usefor j=1:tsif n(i,j)==1if test1(i-(voiceuser+voipuser),j)>=1 & test1(i-(voiceuser+voipuser),j)<=800isdn(i,j)=64000;elseif test1(i-(voiceuser+voipuser),j)>800 & test1(i-(voiceuser+voipuser),j)<=900isdn(i,j)=128000;elseif test1(i-(voiceuser+voipuser),j)>900 & test1(i-(voiceuser+voipuser),j)<=950isdn(i,j)=256000;elseisdn(i,j)=512000;endendendend%Time Slots Vs Bandwidthd=sum(isdn);figure(1);bar(d);xlabel('Time Slots');ylabel('Bandwidth(bps)');%Time Slots Vs Error Ratee=zeros(1,ts);bm=1984000;for i=1:tsif d(i)>bme(i)=d(i)-bm;endendfigure(2);bar(e);xlabel('Time Slots');ylabel('Error Rate(bps)');buff=0;newbw=1984000+buff;prisdn=isdn(1:voiceuser,:);

Page 13: Networks lab manual ecp62

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:tsj=0;bwalloc=0;while (bwalloc<=newbw & jj=j+1;bwalloc=bwalloc+prisdn(j,i);endch=j;if chunservedvoice(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) & chunserveddata(i)=use-ch;endendfigure(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');

Page 14: Networks lab manual ecp62

Exp.No:4 PN sequence generation and testingDate:

Aim:To generate maximal and non-maximal length PN sequence and test its randomness

Properties

Tool Used:

Matlab Coding:

Generation of PN sequence and verification of randomness properties clc;clear all;len = input ('Enter the length of the sequence: ');disp ('Generator Polynomial Example [1 0 0 1...1] ');poly = input ('Enter the polynomial: ');disp ('Initial state Example [1 0 0 1...0]');ini = input ('Enter the initial state: ');ff = log2(len+1);%pn sequence generationa = zeros(len,ff);a(1,(1:ff)) = ini ;for i = 1:(len-1)x = 0;for j = 2:(ff+1)if (poly (1,j) == 1)x = xor (x,a(i,(j-1)));endenda ((i+1),1:ff) = circshift(a(i,1:ff),[0 1]);a ((i+1),1) = x;endfor i = 1:lenh(1,i) = a(i,ff);endfprintf ('The generated sequence is: \n');disp (h);%balance propertycheck = 0;one = 0;zero = 0;for i = 1:lenif ( h(1,i) == 0)zero= zero+1;elseone = one+1;end

Page 15: Networks lab manual ecp62

enddisp ('BALANCE PROPERTY');disp ('Number of ones: ');disp (one);disp ('Number of zeros: ');disp (zero);if ((one-zero) == 1)fprintf ( 'Balance property is satisfied\n\n');elsefprintf ( 'Balance property is not satisfied\n\n');check = 2;end%autocorelation propertywhile (check == 0)for i= 1:leny(i,:) = xor (h,circshift(h,[0 i]));endfor i = 1:lenone = 0;zero = 0;for j = 1:lenif ( y(i,j) == 0 );zero = zero+1;elseone = one+1;endendz(i,1) = zero - one;endfor i = 1: (len-1)g(i,1) = -1;endg (len,1) = len;disp ('AUTOCORRELATION PROPERTY');disp (z);t=1:1:(len);plot(t,z);if(z == g);fprintf ( 'Auto correlation property is satisfied\n\n');check = 3;elsefprintf ( 'Auto correlation property is satisfied\n\n');check = 2;endend% run propertywhile( check == 3);runs = ((len+1)/2);u = ff;r = zeros (1,u);

Page 16: Networks lab manual ecp62

count = 1;for i = 1:len-1if (h(1,i) == h(1,i+1))count = count+1;elser(1,count) = r(1,count)+1;count = 1;endendr(1,count) = r(1,count)+1;s = zeros(1,u);for i = 1:(u-1)s(1,i) = runs / (2.^i) ;ends(1,u) = 1;disp ('RUN PROPERTY');fprintf ('Runs\t\t\t Run Length \n');for i = 1:ufprintf ('%d\t\t\t\t %d\n',r(1,i),i);endif (r == s)fprintf ('Run Property is satisfied\n\n');check = 4;elsefprintf ('Run Property is not satisfied\n\n');check = 2;endendif (check == 2)disp ('The given sequence is not a PN sequence');elsedisp ('The given sequence is a PN sequence');end

Exp.No:5 M/M/I queuing model

Page 17: Networks lab manual ecp62

Date:

Aim:To simulate M/M/I queuing model and obtain

i. Time slot Vs packet loss plot.ii. Maximum and average packet loss without buffer.iii. Buffer size for the given loss.iv. Maximum and average packet loss with buffer

Tool Used:

Matlab Coding:

Generation of M|M|1 modelclc;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 lossn = zeros (1,timeslots);for j = 1:timeslotsif ( tarr(1,j) > tser(1,j) )n(1,j) = ( tarr(1,j) - tser(1,j) ) ;endendbar (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 lossbuff = 0;count = 1;avg_loss(1,count) = avg ;buffer_size(1,count) = buff;while (avg > error_rate)count = count+1;

Page 18: Networks lab manual ecp62

buff = buff+1;tser = tser+1;for j = 1:timeslotsif (n(1,j) > 0)n(1,j) = (tarr(1,j) - tser(1,j));endendavg = mean(n);avg_loss (1,count) = avg;buffer_size (1,count) = buff;enddisp('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');

Exp.No:6 M/G/I and G/G/I queuing model

Page 19: Networks lab manual ecp62

Date:

Aim:To simulate a M/G/I and G/G/I queuing model and obtain

i. Time slot Vs packet loss plot.ii. Maximum and average packet loss without buffer.iii. Buffer size for the given loss.iv. Maximum and average packet loss with buffer

Tool Used:

Matlab Coding:

Generation of M|G|1 modelclc;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 Lossn=zeros(1,timeslots);for j=1:timeslotsif (tarr(1,j)>tser(1,j))n(1,j)=tarr(1,j)-tser(1,j);endendbar(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 Lossbuff=0;count=1;avg_loss (1,count)=avg;buffer_size (1,count)=buff;while (avg>error_rate)

Page 20: Networks lab manual ecp62

count=count+1;buff=buff+1;tser=tser+1;for j=1:timeslotsif (n(1,j)>0)n(1,j)=tarr(1,j)-tser(1,j);endendavg=mean(n);avg_loss(1,count)=avg;buffer_size(1,count)=buff;enddisp('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');

Generation of G|G|1 modelclc;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 Lossn=zeros(1,timeslots);for j=1:timeslotsif(tarr(1,j)>tser(1,j));n(1,j)=tarr(1,j)-tser(1,j);endendbar(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: ');

Page 21: Networks lab manual ecp62

avg=mean(n);disp(avg);%Buffer Size Vs Packet Lossbuff=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:timeslotsif n(1,j)>0n(1,j)=tarr(1,j)-tser(1,j);endendavg=mean(n);avg_loss(1,count)=avg;buffer_size(1,count)=buff;enddisp('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');

Exp.No:7 Encryption and decryption

Page 22: Networks lab manual ecp62

Date:

Aim:To simulate and test the following encryption and decryption algorithm

i. Mono alphabetic cipher- caeser cipher.ii. Poly alphabetic cipher- Trithemius key, Vigenere key, Vigenere plain and cipher

key.iii. RSA with and without digital signature.

Tool Used:

Matlab Coding:

Data Encryption and Decryptionclc;clear all;pt=input('Enter the PlainText: ');asc=double(pt);disp(' ');disp('Monoalphabetic (Caeser Cipher)');disp(' ');shift=input('Enter the Number of End-Around Shifts(key): ');%Encryptionmt=asc;for i=1:length(mt)mt(i)=mt(i)+shift;if mt(i)>127corr=mt(i)-127;mt(i)=32+corr-1;endenddisp(' ');disp('ENCRYPTED TEXT: ');disp(char(mt));%Decryptionfor i=1:length(mt)mt(i)=mt(i)-shift;if mt(i)<32corr=32-mt(i);mt(i)=127-corr+1;endenddisp(' ');disp('DECRYPTED TEXT: ');disp(char(mt));disp(' ');disp('Polyalphabetic(Trithemius Progressive Key): ');%Forming the trithemius key table

Page 23: Networks lab manual ecp62

disp(' ');type=input('Enter the Leftshift(+1) or Rightshift(-1): ');start=32:127;for i=1:96if type==1k=96-i+1;elseif type==-1k=i+1;if i==96k=1;endendfor j=1:96tri(i,j)=start(k);if k==96k=0;endk=k+1;endend%Encryptionmt=asc;for i=1:length(mt)col=mt(i)-31;mt(i)=tri(i,col);enddisp(' ');disp('ENCRYPTED TEXT: ');disp(char(mt));%Decryptionfor i=1:length(mt)col=mt(i)-31;mt(i)=tri(96-i,col);enddisp(' ');disp('DECRYPTED TEXT: ');disp(char(mt));disp(' ');disp('Vignere Key Method: ');disp(' ');key=input('Enter the Key Word: ');keyasc=double(key);keylen=length(key);%Encryptionmt=asc;x=1;for i=1:length(mt)col=mt(i)-31;if type==1row=96-(keyasc(x)-31)+1;

Page 24: Networks lab manual ecp62

if row==0row=96;endelserow=keyasc(x)-31-1;if row==0row=96;endendmt(i)=tri(row,col);if x==keylenx=0;endx=x+1;enddisp(' ')disp('ENCRYPTED TEXT: ');disp(char(mt));%Decryptionx=1;for i=1:length(mt)col=mt(i)-31;if type==1row=(keyasc(x)-31)-1;if row==0row=96;endelserow=96-(keyasc(x)-31-1);if row==0row=96;endendmt(i)=tri(row,col);if x==keylenx=0;endx=x+1;enddisp(' ')disp('DECRYPTED TEXT: ');disp(char(mt));disp(' ');disp('Vignere Auto(plain) Key Method: ');disp(' ');auto1=input('Enter the Key Letter: ');%Encryptionautoasc=double(auto1);mt=asc;for i=1:length(mt)

Page 25: Networks lab manual ecp62

col=mt(i)-31;if type==1row=96-(autoasc-31)+1;if row==0row=96;endelserow=autoasc-31-1;if row==0row=96;endendmt(i)=tri(row,col);autoasc=asc(i);enddisp(' ')disp('ENCRYPTED TEXT: ');disp(char(mt));%Decryptionautoasc=double(auto1);for i=1:length(mt)col=mt(i)-31;if type==1row=(autoasc-31)-1;if row==0row=96;endelserow=96-(autoasc-31-1);if row==0row=96;endendmt(i)=tri(row,col);autoasc=asc(i);enddisp(' ')disp('DECRYPTED TEXT: ');disp(char(mt));disp(' ');disp('Vignere Auto(cipher) Key Method: ');disp(' ');auto1=input('Enter the Key Letter: ');%Encryptionautoasc=double(auto1);mt=asc;for i=1:length(mt)col=mt(i)-31;if type==1row=96-(autoasc-31)+1;

Page 26: Networks lab manual ecp62

if row==0row=96;endelserow=autoasc-31-1;if row==0row=96;endendmt(i)=tri(row,col);autoasc=mt(i);enddisp(' ')disp('ENCRYPTED TEXT: ');disp(char(mt));%Decryptionautoasc=double(auto1);for i=1:length(mt)col=mt(i)-31;if type==1row=(autoasc-31)-1;if row==0row=96;endelserow=96-(autoasc-31-1);if row==0row=96;endendcipkey=mt(i);mt(i)=tri(row,col);autoasc=cipkey;enddisp(' ')disp('DECRYPTED TEXT: ');disp(char(mt));disp(' ')disp('RSA Method: ');disp(' ');mt=asc;n=input('Enter the value of n(public): ');eA=input('Enter the value of eA(public): ');dA=input('Enter the value of dA(secrer): ');eB=input('Enter the value of eB(public): ');dB=input('Enter the value of dB(secrer): ');%Signingfor i=1:length(mt)f=mt(i);mt(i)=1;

Page 27: Networks lab manual ecp62

for x=1:dAmt(i)=mod(mt(i)*f,n);endenddisp(' ');disp('SIGNED TEXT: ');disp(mt);%Encryptionfor i=1:length(mt)f=mt(i);mt(i)=1;for x=1:eBmt(i)=mod(mt(i)*f,n);endenddisp(' ');disp('ENCRYPTED TEXT: ');disp(mt);%Autheniticationfor i=1:length(mt)f=mt(i);mt(i)=1;for x=1:dBmt(i)=mod(mt(i)*f,n);endenddisp(' ');disp('AUTHENICATED TEXT: ');disp(mt);%Decryptionfor i=1:length(mt)f=mt(i);mt(i)=1;for x=1:eAmt(i)=mod(mt(i)*f,n);endenddisp(' ');disp('DECRYPTED TEXT: ');disp(char(mt));

Exp.No:8 Flow control

Page 28: Networks lab manual ecp62

Date:

Aim:To simulate and test

i. Stop and wait protocolii. Go back N protocoliii. Selective repeat protocol

Tool Used:

Matlab Coding:

Stop and Wait Protocol

clc;clear all;disp('SAMPLE INPUT AND OUTPUT: ');n=input('Number of Frames: ');frame=1;while frame<=nfprintf('Transmitting Frame %d\n',frame);s=randint(1,1,15);if s<3fprintf('TIME OUT\n Re-');elseif s>6fprintf('PAK of Frame %d Received\n',frame);frame=frame+1;elsefprintf('NAK of Frame %d Received\n Re-',frame);endend

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==0if flag2==0%Transmitting The Frames In A Windowfor i=1:wfprintf('Frame %d Transmitted\n',a(pt));

Page 29: Networks lab manual ecp62

pt=pt+1;endflag2=1;ends=randint(1,1,10);if s>3fprintf('PAK of Frame %d Received\n',a(pt-w));fprintf('Frame %d Transmitted\n',a(pt));if a(pt)==nflag=1;endpt=pt+1;elsefprintf('NAK Of Frame %d Received\n',a(pt-w));for j=0:w-1fprintf('Frame %d Discarded\n',a(pt-w+j));endpt=pt-w;flag2=0;endend%Last 'W' Frames are dealt seperatelyi=n-w+1;while (i<=n)s=randint(1,1,10);if s>4fprintf('PAK of Frame %d Received\n',a(i));i=i+1;elsefprintf('NAK of Frame %d Received \n',a(i));for j=i:nfprintf('Frame %d Discarded\n',a(j));endfor k=i:nfprintf('Frame %d Transmitted\n',a(k));endendend

Selective Repeat Protocol

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;

Page 30: Networks lab manual ecp62

a=1:n;for i=1:wfprintf('Frame %d Transferred\n',a(i));endwhile flag==0s=randint(1,1,10);if s>3fprintf('PAK of frame %d received\n',a(pt-w));elsefprintf('NAK of frame %d received\n',a(pt-w));ext=ext+1;for i=n+ext:-1:pt+1a(i)=a(i-1);enda(pt)=a(pt-w);endfprintf('Frame %d Transferred\n',a(pt));if a(pt)==nflag=1;endpt=pt+1;endk=pt-w;while flag2==0test=randint(1,1,[1 7]);if flag1==1fprintf('Frame %d Transmitted\n',a(k));flag1=0;endif test>3fprintf('PAK of frame %d received\n',a(k));k=k+1;elsefprintf('NAK of frame %d received\n',a(k));flag1=1;endif k==n+ext+1flag2=1;endend

Exp.No:9 Error control protocol

Page 31: Networks lab manual ecp62

Date:

Aim:To simulate and test

i. Cyclic redundancy checkii. Hamming code

Tool Used:

Matlab Coding:

Exp.No:10 Routing algorithms

Page 32: Networks lab manual ecp62

Date:

Aim:To simulate and test

i. Shortest path routing algorithmii. Hierarchical routing algorithm

Tool Used:

Matlab Coding:

Shortest Path Routing

clc;clear all;n=input('enter the number of nodes: ');conn=input('enter the connected nodes: ');delarr=ones(n);delarr=10000*delarr;len=length(conn);delay2=randint(1,(len/2),[10 50]);k=1;for i=1:2:len;    delarr(conn(i),conn(i+1))=delay2(k);    delarr(conn(i+1),conn(i))=delay2(k);    k=k+1;endfor i=1:n    delarr(i,i)=0;enddisp('....Delay time.....');disp(delarr);gr=delarr;v=[1:n];p=perms(v);start=input('enter the source node: ');dest=input('enter the destination node: ');

%finding all possible paths and thier delayspaths=zeros(factorial(n-1),n);index=0;for i=1:factorial(n);    if p(i,1)~=start;        continue;    end    de=0;    temp=p(i,1);    index=index+1;

Page 33: Networks lab manual ecp62

    paths(index,1)=temp;    for j=2:n;        if(gr(temp,p(i,j))>0 && gr(temp,p(i,j))<1000);            flag=1;            de=de+gr(temp,p(i,j));            temp=p(i,j);            paths(index,j)=temp;            if temp == dest                delay(index)=de;                break;            end        else            flag=0;            index=index-1;            break;        end;    end;end;%removing the repeated pathsj=1;delay1(j)= delay(1);paths1(j,:) = paths(1,:);for i=2:length(delay);    if delay(i-1)~=delay(i);        j=j+1;        delay1(j)=delay(i);        paths1(j,:)=paths(i,:);        shortind=j;    end;end;

%displaying all paths and also the delayfor i=1:length(delay1);    for j=1:n;        if paths1(1,j)~=0;            fprintf('%d->',paths1(i,j));        else            break;        end;    end;    fprintf('\b\b:delay=%d\n',delay1(i));end;

temp=min(delay1(1));

for i=1:length(delay1)    if delay1(i)==temp        break;    endend

Page 34: Networks lab manual ecp62

disp('');for j=1:n    if paths1(i,j)~=0            fprintf('%d->',paths1(i,j));    endendfprintf('\b\b\t\t delay=%d\n',delay1(i));

Shortest & Distance Vector Routing

clc;clear all;n=input('enter the number of nodes');conn=input('enter the connected nodes');delarr=ones(n);delarr=10000*delarr;len=length(conn);delay2=1;

for i=1:2:len;    delarr(conn(i),conn(i+1))=delay2;    delarr(conn(i+1),conn(i))=delay2;   endfor i=1:n    delarr(i,i)=0;enddisp('....Delay time.....');disp(delarr);gr=delarr;v=[1:n];p=perms(v);start=input('enter the source node');dest=input('enter the destination node');

%finding all possible paths and thier delayspaths=zeros(factorial(n-1),n);index=0;for i=1:factorial(n);    if p(i,1)~=start;        continue;    end    de=0;    temp=p(i,1);    index=index+1;    paths(index,1)=temp;    for j=2:n;        if(gr(temp,p(i,j))>0 && gr(temp,p(i,j))<1000);

Page 35: Networks lab manual ecp62

            flag=1;            de=de+gr(temp,p(i,j));            temp=p(i,j);            paths(index,j)=temp;            if temp == dest                delay(index)=de;                break;            end        else            flag=0;            index=index-1;            break;        end;    end;end;%removing the repeated pathsj=1;delay1(j)= delay(1);paths1(j,:) = paths(1,:);for i=2:length(delay);    if delay(i-1)~=delay(i);        j=j+1;        delay1(j)=delay(i);        paths1(j,:)=paths(i,:);        shortind=j;    end;end;

%displaying all paths and also the delayfor i=1:length(delay1);    for j=1:n;        if paths1(1,j)~=0;            fprintf('%d->',paths1(i,j));        else            break;        end;    end;    fprintf('\b\b:delay=%d\n',delay1(i));end;%shortest path and its delaydisp('');disp('the shortest path is');for j=1:n;    if paths1(shortind,j)~=0;        fprintf('%d->',paths1(shortind,j));    else        break;    end;end;fprintf('\b\b\t\t delay=%d\n',delay1(shortind));

Page 36: Networks lab manual ecp62
Page 37: Networks lab manual ecp62

Exp.No:11 Routing algorithmsDate:

Aim:To study, generate and trace the following PDF

i. Gaussian distributionii. Uniform distributioniii. Exponential distributioniv. Rayleigh distributionv. Binomial distributionvi. Negative binomial distributionvii. Gamma distributionviii. Poisson distribution

Tool Used:

Matlab Coding:

i. Gaussian distribution

clear x h b;figure, hold on;mu = [-3 -1 2];beta = [1 5 2];rho = [1 2 10];delt = 0.15;cents = -12:delt:12;for k = 1:length(mu) x(k,:) = gg6(1,100000,mu(k),beta(k),rho(k)); h(k,:) = histc(x(k,:),cents);endbar(cents,h(1,:)/(100000*delt),'b');bar(cents,h(2,:)/(100000*delt),'g');bar(cents,h(3,:)/(100000*delt),'r');xlim([-8 8]); set(gca,'XTick',-10:10);set(gca,'fontsize',14);xlabel('\itx \rm(bin)'); ylabel('normalized histogram');

ii) Uniform Distribution: %Uniform Distributionclc;close all;clear all;n=input('Input the end value of x = ');

Page 38: Networks lab manual ecp62

a=input('Input the starting value of uniform distribution, a=');b=input('Input the ending value of uniform distribution, b= ');y=1/(b-a);m=(a+b)/2;s=((b-a)^2)/12;disp('mean is ');mdisp('variance is ');sdisp('value of f(x) is ');yu=[zeros(1,(a-1)) ones(1,(b-a)) zeros(1,(n-b))];z=y*u;stem(z);axis([0 n 0 1]);

iii) Hyper-exponential distribution:

t=0:0.01:6; miu=1; pi1=.0526; miu1=.1; miu2=2.0; pi2=1-p1;F=pi1*(1-exp(-miu1*t))+pi2*(1-exp(-miu2*t)); E=1-exp(-t/miu);f=pi1*miu1*exp(-miu1*t)+pi2*miu2*exp(-miu2*t);e=1/miu*exp(-t/miu); subplot(2,1,1); plot(t,F,'k'); hold on;plot(t,E,'k'); xlabel('t'); ylabel('F(t)'); title('A two-stagehyper-exponential distribution'); text(.3,.8,'H_{2}');text(1,.5,'Exp'); subplot(2,1,2); plot(t,f,'k'); hold on;plot(t,e,'k'); xlabel('t'); ylabel('f(t)'); text(.3,1.4,'H_{2}');text(1,.5,'Exp');

iv) Rayliegh Distribution:

%Rayliegh Distributionclc;close all;clear all;x=input('Enter the input sequence ');s=input('Enter the standard deviation ');n=length(x);a=(x.^2)./(2*(s^2));p=x./s;q=exp(-a);y=p.*q;t=0:n-1;plot(t,y);title('Rayliegh Distribution');grid on;

v) Binomial Distribution:Distribution in stem:

k=0:20;y=binopdf(k,20,0.5);stem(k,y)Distribution in stair:

Page 39: Networks lab manual ecp62

k=0:20;y=binocdf(k,20,0.5);stairs(k,y)grid on

vi Negative binomial distribution:

p=.5; j=0:35; jj=0:.1:35; i=1;for r=[0.5 1 2 4 8 16 32]P=gamma(r+j)./gamma(r)./gamma(j+1).*(p^r).*((1-p).^j);PP=gamma(r+jj)./gamma(r)./gamma(jj+1).*(p^r).*((1-p).^jj);plot(j,P,'.k',jj,PP,'k');hold on;end text(.4, 0.65,'r=0.5'); text(1.2, 0.3,'r=1'); text(2,0.22,'r=2');text(3.8, 0.17,'r=4'); text(8, 0.13,'r=8'); text(17,0.1,'r=16'); text(32, 0.08,'r=32');ylabel('P[X_{r}=j]');xlabel('j'); title('The generalized negative binomial distribution');

vii) Gamma distribution:

y=0:0.01:4.5; for b = [0.2 1 5]a=b;f=a*(a*y).^(b-1)/gamma(b).*exp(-a*y);if b==.2plot(y,f,'--k');elseplot(y,f,'k');endhold on;end;axis([0,4.5,0,2]); xlabel('y'); ylabel('f_{Y\beta}(y)');text(.1,1.6,'\beta=\alpha=0.2'); text(.17,.95,'\beta=\alpha=1');text(1.2,.8,'\beta=\alpha=5');

viii) Poisson distribution:

k=0:25; kk=0:.1:25; P=zeros(1,26);for l=[0.5 1 2 4 8 16]P=l.^k./gamma(k+1)*exp(-l);PP=l.^kk./gamma(kk+1)*exp(-l);plot(k,P,'k.',kk,PP,'k');hold on;endaxis([0, 25, 0, 0.65]); text(0.6,0.47,'\lambda=0.5');text(1.4,0.37,'\lambda=1'); text(2.4,0.27,'\lambda=2');text(4.9,0.18,'\lambda=4'); text(9,.145,'\lambda=8');text(18.2,.1,'\lambda=16');ylabel(texlabel('P(k;lambda)'));

Page 40: Networks lab manual ecp62

xlabel('k'); title('Poisson distribution with different values of \lambda');

OUTPUT: